0
所以我有這個plnkr。我試圖找出如何讓用戶能夠提交表單,儘管有一個空的「項目組」即用戶可以提交儘管同時有item.foo
和item.bar
空,但不是當一個表單控件isn' t空了。
所以我有這個plnkr。我試圖找出如何讓用戶能夠提交表單,儘管有一個空的「項目組」即用戶可以提交儘管同時有item.foo
和item.bar
空,但不是當一個表單控件isn' t空了。
改變你的模板是:
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被評估爲真時,需要make foo。並且僅當foo被評估爲真時才使欄需要