Validate object's class instance type in Angular HTML template
npm install @ngx-toolset/template-type-checker



- @ngx-toolset/template-type-checker
- Features
- Installation
- NPM
- Usage
- Module Import
- TS
- HTML
- Possibility to validate object's class instance type in HTML template
npm install @ngx-toolset/template-type-checker --save
Choose the version corresponding to your Angular version:
| Angular | @ngx-toolset/template-type-checker |
|---------|------------------------------------|
| 14.x.x | >=0.0.1 <=1.0.0-rc.9 |
| 15.x.x | 1.0.0-rc.10 |
| 16.x.x | >=1.0.0-rc.11 <=2.x.x |
| 17.x.x | 3.0.0 |
Import the TypeCheckerPipe in the component(s) you would like to use it:
``ts
import { Component } from '@angular/core';
import { TypeCheckerPipe } from '@ngx-toolset/template-type-checker';
@Component({
selector: 'app-sample',
templateUrl: 'sample.component.html',
styleUrls: ['sample.component.scss'],
standalone: true,
imports: [TypeCheckerPipe],
})
export class SampleComponent {}
`
`ts
import { Component } from '@angular/core';
import { TypeCheckerPipe } from '@ngx-toolset/template-type-checker';
class ClassA {}
class ClassB {}
@Component({
selector: 'app-sample',
templateUrl: './sample.component.html',
styleUrls: ['./sample.component.scss'],
standalone: true,
imports: [TypeCheckerPipe],
})
export class SampleComponent {
public classA: typeof ClassA;
public classB: typeof ClassB;
public sampleObject: ClassA;
public constructor() {
this.classA = ClassA;
this.classB = ClassB;
this.sampleObject = new ClassA();
}
}
`
`html
This div will be rendered.