Apply a directive conditionally

前端 未结 15 1970
别跟我提以往
别跟我提以往 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:35

    As at 18th Jan 2019, This is how I added a directive conditionally in Angular 5 and above. I needed to change the color of the component based on darkMode. If the page was in dark mode or not.

    This worked for me:

    I hope this helps someone.

    EDIT

    This changes the value of an attribute (color) based on a condition. It just happens that the color is defined using a directive. So anyone reading this please do not get confused, this is not applying a directive conditionally (ie. which means adding or removing a directive to the dom based on a condition)

提交回复
热议问题