更新时间:2022-12-27 13:07:47
在某些情况下,我们需要像这样动态添加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>
{{}}(称为插值)和[](称为属性绑定)均表示对角度的理解,即从数据源到查看目标之间存在单向.
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
For more visit www.codementor.io