我有一个像这样的条件字段:
<form ng-app="myApp" name="frm">
<select ng-model="NewBranchRequest.BranchTypeCode">
<option selected="selected" value="0">third</option>
<option value="1">first</option>
<option value="2">second</option>
</select>
<input class="ng-pristine ng-valid" type="text" name="power" ng-model="NewBranchRequest.PwrCnt" placeholder="sad" ng-required="NewBranchRequest.BranchTypeCode==0">
<span style="color:red" ng-show="frm.power.$invalid">
*
</span>
<button>Submit</button>
</form>
Demo
它可以工作,但是从服务器填充选项并且它不起作用。
更新
检查这个Demo 这不起作用。
我想要的只是在选择列表中选择Bug后,输入所需的内容。
有什么想法吗?
最佳答案
在 http://jsfiddle.net/sadeghbayan/MTfRD/1452/
改变
ng-required="form.type==0"
到
ng-required="form.type=='bug'"
我在这里进行了更改:http://jsfiddle.net/MTfRD/1453/
<小时/>另外,如果你想获取form.type中的json对象你可以改变这个
ng-options='option.value as option.name for option in typeOptions'
到
ng-options='option.value for option in typeOptions'
关于javascript - Angular : Conditional field doesn't work with server side,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27223542/