如何在angularjs中做条件maxlength

有没有人知道如何在
angularjs中做条件maxlength,我发现条件需要但不是maxlength等….

例如,如果maxlength给定…它应该验证但是如果maxlength是0或false,它不应该….

$scope.validation = {a: {required:true,minlength:5, maxlength:10}, 
                     b: {required:false,minlength:0, maxlength:false}}

Html使用ng-repeat循环创建….现在问题是每次都会激活maxlength …而我已经为第二个输入字段禁用了它

<input type="text" name="myName" ng-model="name" ng-minlength='validation.a.minlength' ng-maxlength="validation.a.maxlength" ng-required='validation.a.required'  />


<input type="text" name="myName1" ng-model="name1" ng-minlength='validation.b.minlength' ng-maxlength="validation.b.maxlength" ng-required='validation.b.required' />

最佳答案 如果通过角度表达式将空字符串用作“false”,则这些参数似乎有效.

<input type="text" name="myName" ng-model="name" ng-minlength='{{validation.a.minlength}}' ng-maxlength="{{validation.a.maxlength}}" ng-required='validation.a.required'  />
<input type="text" name="myName1" ng-model="name1" ng-minlength='{{validation.b.minlength}}' ng-maxlength="{{validation.b.maxlength}}" ng-required='validation.b.required' />

  $scope.validation = {
    a: {required:true, minlength:5, maxlength:10}, 
    b: {required:false, minlength:'', maxlength:''}
  }

plunker

plunker为1.3.2

现在可以使用0和Number.MAX_SAFE_INTEGER忽略此规则.或者也许只有999就够了:)

 b: {required:false, minlength:0, maxlength:Number.MAX_SAFE_INTEGER}
点赞