我在转发器中有一个下拉列表,应该切换我的自定义“必需”属性.我尝试了ng-show但是display =“none”属性就是所有添加的.我的选择是: –
1-添加/删除输入字段并设置bird.Stuff,而不仅仅是隐藏它,因为它仍然是必需的.
JS
$scope.validateParticipants = function (type) { if (type == "Single") { this.donation.Participants = "1"; } else this.donation.Participants = ""; }
HTML
<div ng-repeat="bird in animalTest.birds"> @(Html.DropDownList("Type",(IEnumerable<SelectListItem>)ViewBag.BirdList,new { ng_model = "bird.Type",ng_change = "validaterequired(bird.Type)",required = "Type is required" })) ... <input data-ng-show="bird.Type == 'Endangered'" id="stuff" type="number" data-ng-model="bird.Stuff" required = "Number of Volunteers required"/> </div>
我在这里先向您的帮助表示感谢!
解决方法
使用
ng-required.这将采用角度表达式,并在表达式为true时添加必需的属性.
<input type="number" data-ng-model="bird.Stuff" ng-required="donation.Participants > 0"/>