Apply a directive conditionally

前端 未结 15 1967
别跟我提以往
别跟我提以往 2020-11-27 15:11

I am using Material 2 to add md-raised-button. I want to apply this directive only if certain condition becomes true.

For example:

<         


        
15条回答
  •  心在旅途
    2020-11-27 15:37

    Use NgClass

    [ngClass]="{ 'mat-raised-button': trueCondition }"
    

    example of true condition:

    this.element === 'Today'
    

    or a boolean function

    getTruth()
    

    full example:

      
    

    If you want a default class:

      
    

提交回复
热议问题