我在angularjs中有2个表单和2个状态。表单1(状态1)包含输入,例如:input,select ...并且在提交form1时显示表单2(状态2)。 form2中的所有字段都是表单1中的相同字段,但必须禁用它们。我将所有字段从表单1传递到表单2,使用$stateParams
,如vm.fields = $stateParams.fieldForm1
;那么我该怎样做才能禁用表单2
答案 0 :(得分:1)
如果形式有角度,则需要设置一个名为formState
的选项。
<body ng-app="formlyExample" ng-controller="MainCtrl as vm">
<div>
<formly-field options="vm.checkboxField" model="vm.options.formState"></formly-field>
</div>
</body>
在控制器级别,你必须像这样设置formState:
(function() {
'use strict';
var app = angular.module('formlyExample', ['formly', 'formlyBootstrap']);
app.controller('MainCtrl', function MainCtrl($scope, formlyVersion) {
vm.env = {
angularVersion: angular.version.full,
formlyVersion: formlyVersion
};
var vm = this;
vm.options = {
formState: {
disabled: true
}
}
});
})();
要为所有字段更新formState,请执行以下操作:
angular.forEach(vm.fields, function(field) {
field.expressionProperties = field.expressionProperties || {};
field.expressionProperties['templateOptions.disabled'] = 'formState.disabled';
});
答案 1 :(得分:0)
使用fieldGroup时的真实答案。在控制器中:
vm.options = {
formState: {
disabled: true
}
};
angular.forEach(vm.fields, function(field) {
if(field.fieldGroup == null) {
field.expressionProperties = field.expressionProperties || {};
field.expressionProperties['templateOptions.disabled'] = 'formState.disabled';
}else {
var i = 0;
for(i=0; i< field.fieldGroup.length; i++){
field.fieldGroup[i].expressionProperties = field.fieldGroup[i].expressionProperties || {};
field.fieldGroup[i].expressionProperties['templateOptions.disabled'] = 'formState.disabled';
}
}
});