MrM*_*MrM 4 angularjs angularjs-directive angularjs-ng-change
我在转发器中有一个下拉列表,应该切换我的自定义"必需"属性.我尝试了ng-show但是display ="none"属性就是所有添加的.我的选择是: -
1-添加/删除输入字段并设置bird.Stuff,而不仅仅是隐藏它,因为它仍然是必需的.
2-在输入字段上添加/删除"required"属性.
JS
$scope.validateParticipants = function (type) {
if (type == "Single") {
this.donation.Participants = "1";
}
else
this.donation.Participants = "";
}
Run Code Online (Sandbox Code Playgroud)
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>
Run Code Online (Sandbox Code Playgroud)
我在这里先向您的帮助表示感谢!
使用ng-required.如果表达式为true,则采用角度表达式并添加必需属性.
<input type="number" data-ng-model="bird.Stuff" ng-required="donation.Participants > 0"/>
Run Code Online (Sandbox Code Playgroud)