所以我有这个普朗克。我试图弄清楚如何允许用户在有一个空的"item组“的情况下提交表单,也就是说,尽管item.foo和item.bar都是空的,但当其中一个窗体控件不是空的时候,用户仍然能够提交表单。
发布于 2015-03-03 05:08:22
将模板更改为:
angular.module('plunker', []).controller('MainCtrl', function($scope) {
$scope.myModel = {};
$scope.myModel.items = [];
$scope.myModel.items.push({ foo: 'foo', bar: 'bar' });
}).directive('myDirective', function() {
return {
require: 'ngModel',
scope: {
myModel: '=ngModel',
},
link: function(scope, elem, attrs, modelCtrl) {
},
template: '<ng-form name="add">' +
'<input type="text" name="foo" ng-required="myModel.bar" ng-model="myModel.foo" />' +
'<input type="text" name="bar" ng-required="myModel.foo" ng-model="myModel.bar" />' +
'</ng-form>',
}
})请注意ng必需的属性。
这基本上意味着在把bar计算为true时需要make。并仅在foo求值为true时才使bar成为必需的。
看看这里的直播:http://plnkr.co/edit/pCq8MfgLkZALaWcRLLNz?p=preview
https://stackoverflow.com/questions/28824243
复制相似问题