我需要根据控件属性将条件类添加到表单字段。
例如:我的控制器中有
$scope.isIssueFixed = true;
而我的形式对象是——
$scope.formly = {类名: 'col-xs-6',键:"名称",类型:"输入",模板选项:{标签:"通用设备名称"}
现在我们如何将条件类添加到上面的表单字段,$scope.isIssueFixed?"确定":"否";在形式上对象?
我以角度形式使用包装器解决了这个问题。这是我做的代码。也许对某人有帮助。
将 bolow 代码添加到配置中:
formlyConfigProvider.setWrapper({
name: 'horizontalBootstrapLabel',
template: [
`<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>`
].join(' ')
});
$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'
}
});
您可以使用 angularjs 的 ng-class 指令。裁判 https://docs.angularjs.org/api/ng/directive/ngClass。