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

前端 未结 3 1008
小蘑菇
小蘑菇 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:46

    As @Edric specified here, the matter is the binding target. I firstly thought all of these are handled by a built-in directive

    [attr.role]
    [class.extra-sparkle]
    [style.width.px]
    

    like ngClass and ngStyle but it is not. None of these are directives, they are just synonyms of this:

    bind-attr.role
    bind-class.extra-sparkle
    bind-style.width.px
    

    and the bind prefix are compiled at template parser here. The "bind thing" is not a directive, it is build-in feature that compiler already handles all the bound properties, attributes etc.

提交回复
热议问题