AngularJS:ng-show / ng-hide必填字段

前端之家收集整理的这篇文章主要介绍了AngularJS:ng-show / ng-hide必填字段前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。
我试图使用ng-show / ng-hide显示/隐藏必填字段,除非选中输入以显示字段.但是,表单不会提交,因为需要隐藏字段(除非我选择查看隐藏的附加字段的选项).我在必填字段上使用ng-hide的原因是显示仅在需要时可能需要的其他字段.有没有一种方法可以动态更改“隐藏”输入的属性

例:

Check Me to Show Additional Fields
<input type="checkBox" ng-model="checked">

Additional Fields
<input type="number" class="form-control" id="inputamount" data-ng-model="itemamount" step="any" required ng-show="checked"/>
<input type="text" class="form-control" id="inputlocation" data-ng-model="itemlocation" placeholder="Location" required ng-show="checked"/>

解决方法

你可以使用ng-required,它会设置所需的属性,并与输入模型的已检查的boleon相对应

<input type="number" ng-required="{{checked}}" class="form-control" id="inputamount"
 data-ng-model="itemamount" step="any" ng-show="checked"/>

猜你在找的Angularjs相关文章