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; });
@Component({ selector: "app-root", template: ` <div [ngClass]=" header? 'country-header' : 'country-header-link'"> Hello </div> ` }) export class AppComponent implements AfterViewInit { ngAfterViewInit(): void { setTimeout(() => { this.jerry = "changed!"; }, 0); } jerry = "Jerry Hello"; header = true; }
最后在函数_applyIterableChanges里,给div标签添加class: