kittencup / angular2-ama-cn

angular2 随便问
691 stars 101 forks source link

模板语法中的property绑定和attribute绑定有什么区别呢? #101

Open helloyxw opened 8 years ago

helloyxw commented 8 years ago

property绑定,如: <img [src]="heroImageUrl"> attribute绑定,如:

One-Two

请问有什么区别? 或者说property和attribute有什么区别?

kittencup commented 8 years ago

都一样,只不过angular2会针对前缀为attr.class.style.的单独做处理

adu8419 commented 8 years ago

官网有说明,读完后 感觉只可意会不可言传

adu8419 commented 8 years ago

有影响的一句话: angular2 无 attribute

adu8419 commented 8 years ago

在Angular 2的世界中,Attribute唯一的作用是用来初始化元素和指令的状态。 当进行数据绑定时,我们只是在与元素和指令的Property和事件打交道,而Attribute就完全靠边站了。 In the world of Angular 2, the only role of attributes is to initialize element and directive state. When we data bind, we're dealing exclusively with element and directive properties and events. Attributes effectively disappear.

Imporial commented 8 years ago

遇到过所谓 “非原生”属性 必须使用 [attr.属性名] 的问题