Location of ngClass definition:
export declare class NgClass implements DoCheck {
private _iterableDiffers;
private _keyValueDiffers;
private _ngEl;
private _renderer;
private _iterableDiffer;
private _keyValueDiffer;
private _initialClasses;
private _rawClass;
constructor(_iterableDiffers: IterableDiffers, _keyValueDiffers: KeyValueDiffers, _ngEl: ElementRef, _renderer: Renderer2);
set klass(value: string);
set ngClass(value: string | string[] | Set<string> | {
[klass: string] :any;
});
Copy the code
A practical example:
@Component({
selector: "app-root".template: `
Hello
`
})
export class AppComponent implements AfterViewInit {
ngAfterViewInit(): void {
setTimeout(() = > {
this.jerry = "changed!";
}, 0);
}
jerry = "Jerry Hello";
header = true;
}
Copy the code
Finally, in the _applyIterableChanges function, add a class to the div tag:
More of Jerry’s original articles can be found in “Wang Zixi” :