Multiple classes in ngClass

后端 未结 3 1322
渐次进展
渐次进展 2021-02-07 20:52

I\'m trying to add multiple values in *ngClass, what used to work on previous alpha releases and doesn\'t seem to work now on angular2 beta:



        
3条回答
  •  悲哀的现实
    2021-02-07 21:10

    If you aren't going to be changing these classes dynamically then using ngClass is overkill. You can simply use class="fa fa-star" in your template.

    ngClass should be used when you when you want to switch these on and off dynamically. There's an example in the docs:

    Your component would have a method:

    setClasses() {
      return {
        saveable: this.canSave,      // true
        modified: !this.isUnchanged, // false
        special: this.isSpecial,     // true
      }
    }
    

    then use ngClass in your template like so:

    This div is saveable and special

提交回复
热议问题