且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

Angular 2:带括号和不带括号的属性绑定之间的区别?

更新时间:2022-12-27 13:03:44

有些情况我们需要动态添加这样的 html 属性可能是来自 api 请求的 json 的示例

There are some Cases where we need to add like this html attributes dynamically might be and example which comes json from api request

案例 1 [] 称为属性绑定

<my-comp [foo]="data.bar"></my-comp>

情况 2 {{ }} 称为插值

<my-comp foo="{{data.bar}}"></my-comp>

情况 3 条件处理

<my-comp [attr.foo]="data.bar ? true : false"></my-comp>

{{ }} 称为 Interpolation 和 [] 称为 Property Binding 意味着 angular 都知道从数据源到查看目标是单向的.

Both {{ }} called as Interpolation and [] called as Property Binding means angular understand that there is One-way from data source to view target.

更多信息请访问 www.codementor.io一个>