首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >ng-重复指令和$validators

ng-重复指令和$validators
EN

Stack Overflow用户
提问于 2015-03-03 04:42:13
回答 1查看 26关注 0票数 0

所以我有这个普朗克。我试图弄清楚如何允许用户在有一个空的"item组“的情况下提交表单,也就是说,尽管item.fooitem.bar都是空的,但当其中一个窗体控件不是空的时候,用户仍然能够提交表单。

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2015-03-03 05:08:22

将模板更改为:

代码语言:javascript
复制
    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

票数 2
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/28824243

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档