Angular2 ngStyle多类绑定不起作用

时间:2016-06-15 16:02:11

标签: angular angular2-template

我有一个动态创建某个表单的应用程序,使用angular2 ans bootstrap 3.当我尝试使用引导网格动态调整组件样式时,我遇到了一些麻烦。

我写了这个:

[ngStyle]="['col-xs-12','col-sm-'+field.span,'col-md-'+field.span,'col-lg-'+field.span]"

'field'被正确限制,我没有错误,'span'属性是1到12之间的数字,探索div似乎没有样式。

1 个答案:

答案 0 :(得分:1)

ngStyle具有不同的目的或使用方式不同。看来你想要的是ngClass

[ngClass]="['col-xs-12','col-sm-'+field.span,'col-md-'+field.span,'col-lg-'+field.span]"

ngStyle用例类似于

[ngStyle]="{color: someColorProperty}"