2017-04-06 100 views
0

我需要基於控件屬性添加條件類到Form字段。如何爲基於控制器屬性的formly-field添加動態類?

防爆:我在我的控制器

 $scope.isIssueFixed = true;

和我formly對象 -

 
$scope.formly = { 
className: 'col-xs-6', 
key: 'Name', 
type: 'input', 
templateOptions: { 
label: 'Common Device Name' 
} 

現在,我們如何才能增加一個條件類以上formly場, $ scope.isIssueFixed ? 'OK': '不';在形式上的對象?

回答

0
$scope.$watch('isIssueFixed', function() { 
     var classAdded = $scope.isIssueFixed ? "ok" , "No"; $scope.formly = { 
       className: 'col-xs-6 ' + classAdded , 
       key: 'products.device[0].deviceCommonName', 
       type: 'input', 
       templateOptions: { 
       label: 'Common Device Name' 
       } 
    }); 
+0

上面的解決方案不工作,我需要動態添加基於條件的類,在上面的解決方案類中,如果控件屬性發生更改,將不會更新。謝謝回答。每當scope.Isuefixed更改我wnat更新類的形式 –

+0

更新了答案現在試試1 –

0

我使用Wrappers以角度形式解決了這個問題。這是我需要的代碼。可能對某人有幫助。

添加bolow代碼來配置:

formlyConfigProvider.setWrapper({ 名: 'horizo​​ntalBootstrapLabel', 模板: <label for="{{::id}}" class="col-sm-2 control-label" > '{{to.label}} {{to.required ? "*" : ""}} </label> <div class="col-sm-8" ng-class="{'bbb':model.heightlight}"> <formly-transclude></formly-transclude> </div> ]。加入(」「) });