在ngClass中动态绑定值

时间:2018-07-11 12:41:35

标签: javascript angular interpolation angular6 ng-bind

我如何在ngClass中动态添加价值?我现在要在组件文件中添加一个名为labelClass的变量,我想在ngClass中添加它。我尝试使用插值方法但遇到解析错误,因此如何将值动态绑定到属性?

<label for="fddTimeslot" 
       class="control-label" 
       [ngClass]="{'col-lg-4 col-xs-8' : !labelClass, {{labelClass}}: 
                  !!labelClass}"> {{label}} 
</label>

错误:

Parser Error: Got interpolation ({{}}) where expression was expected 
at column 36 in [{'col-lg-4 col-xs-8' : !labelClass, {{labelClass}}: !!labelClass}] 
in ng:///AppModule/FilteringDropdownListSelectorComponent.html@12:18
("SelectorActionButton}"> 
   <label for="fddTimeslot" 
          class="control-label"
          [ERROR ->][ngClass]="{'col-lg-4 col-xs-8' : !labelClass,
                               {{labelClass}}: !!labelClass}">
                               {{label}"): 
      ng:///AppModule/FilteringDropdownListSelectorComponent.html@12:18

0 个答案:

没有答案