角度:条件字段不适用于服务器端

Angular: Conditional field doesn't work with server side

本文关键字:适用于 服务器端 不适用 字段 条件 角度      更新时间:2023-09-26

>我有一个这样的条件字段:

<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>  

演示
它有效,但从服务器填充选项,它不起作用。

更新
检查此演示,它不起作用。

我想要的只是在选择列表中选择错误后,输入得到要求.

知道吗?

In 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'