【发布时间】:2016-04-27 10:06:50
【问题描述】:
我的角度 ng-options 指令不起作用。更改选项时,ng-model 不会更新。
角度 sn-ps
scope.searchoptions = [
{ name: "All", id: 1 },
{
name: "Devices",
id: 2
}, {
name: "Sessions",
id: 3
}, {
name: "Alerts",
id: 4
},{
name: "Files",
id: 5
}];
scope.currentSearch = scope.searchoptions[0]; // Intial object
// Html 片段
<div class="form-group l-h m-a-0">
<select class="form-control"
ng-options="item.name for item in searchoptions track by item.id"
ng-model="currentSearch">
</select>
</div>
给定的代码在选择选项时没有更新模型
请注意:在我的具体情况下,ng-init 对我来说失败了。问题是我正在使用的值在 ng-init 运行时尚不可用:我通过 ajax 调用获得了值,此时 ng-init 已经完成
【问题讨论】:
-
该问题与子范围问题有关
标签: javascript angularjs angular-directive angularjs-ng-options