具有ng选定问题的Angularjs ng-init

时间:2015-07-03 07:58:53

标签: angularjs

在以下代码中,如果ng-selected值未变为True,那么为什么ng-init不会选择option value=3。如果ng-selected变为true,则应显示选择的值,否则为默认值,即选项3

右下拉显示未选择任何选项。

<select class="form-control" name="issue" id="issue" ng-model="item.issue" ng-init="item.issue='3'">
     <option value="3" ng-selected="item.issue['id'] == '3'">Task</option>
     <option value="4" ng-selected="item.issue['id'] == '4'">Task4</option>
</select>

2 个答案:

答案 0 :(得分:2)

ng-init中,您将issue设为'3',而不是item.issue.id

<select class="form-control" name="issue" id="issue" ng-model="item.issue" ng-init="item.issue.id='3'">
     <option value="3" ng-selected="item.issue['id'] == '3'">Task</option>
     <option value="4" ng-selected="item.issue['id'] == '4'">Task4</option>
</select>

答案 1 :(得分:0)

我认为ng-init应该设置id

的值
<select class="form-control" name="issue" id="issue" ng-model="item.issue" ng-init="item.issue.id='3'">
     <option value="3" ng-selected="item.issue['id'] == '3'">Task</option>
     <option value="4" ng-selected="item.issue['id'] == '4'">Task4</option>
</select>