Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/angular/26.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
angular 2如何仅在满足条件时添加元素属性_Angular - Fatal编程技术网

angular 2如何仅在满足条件时添加元素属性

angular 2如何仅在满足条件时添加元素属性,angular,Angular,对于Angular 2,仅当满足条件时才添加元素属性的语法是什么。 我曾考虑使用*ngIf,但它只是添加或删除整个元素。取决于属性。 一般语法是[property]=“value或condition” 例如: [class.myclass]="condition" [style.height]="value" [selected]="condition" 其中条件和值是javascript表达式。谷歌搜索“Angular 2模板语法”

对于Angular 2,仅当满足条件时才添加元素属性的语法是什么。 我曾考虑使用*ngIf,但它只是添加或删除整个元素。

取决于属性。 一般语法是
[property]=“value或condition”

例如:

[class.myclass]="condition" [style.height]="value" [selected]="condition"
其中条件和值是javascript表达式。谷歌搜索“Angular 2模板语法”