How [class] [attr] [style] directives work

前端 未结 3 1004
小蘑菇
小蘑菇 2020-12-17 02:58

I examined ngStyle, ngClass directives here but I still couldn\'t understand how these work:

3条回答
  •  遥遥无期
    2020-12-17 03:37

    The following code snippets are excerpted from the Angular.io docs.

    What you're referring to is the Binding target.

    
    

    The first div is referencing Attribute binding.

    One-Two

    The second div is referencing Class binding.

    
    
    The class binding is special
    This one is not so special

    However, it is recommended to use NgClass.

    The last div is referencing Style binding. Believe it or not, the third div is actually legal (or at least in Angular).

    
    
    

    However, it is recommended to use NgStyle instead.

    So, in this case, it will bind the value of the variable to the element. (Except the class where it will evaluate whether the isDelightful variable is true.)

    Here's a Stackblitz demo for you to play around with. :)

提交回复
热议问题