Difference between [ngClass] vs [class] binding

前端 未结 4 2170
谎友^
谎友^ 2020-11-27 17:12

What is the difference in Angular 2 between the following snippets:

4条回答
  •  野性不改
    2020-11-27 17:35

    This is special Angular binding syntax

    This is part of the Angular compiler and you can't build a custom binding variant following this binding style. The only supported are [class.xxx]="...", [style.xxx]="...", and [attr.xxx]="..."

    ngClass is a normal Angular directive like you can build it yourself

    ngClass is more powerful. It allows you to bind a string of classes, an array of strings, or an object like in your example.

提交回复
热议问题