Angular里ngClass的一个使用例子

Angular里ngClass的一个使用例子

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:

Angular里ngClass的一个使用例子

Angular里ngClass的一个使用例子


上一篇:Java虚拟机之内存区域(1)


下一篇:JS浮点数运算时的bug问题分析与解决方法