我想使用 AngularJS 来使用 ng-options 进行选择,但它似乎没有像我想要的那样工作......
Below you can see javascript code, which contain from creating array and also view, where ng-options are using.
var vm = this;
vm.selectedUser;
vm.userDatas = [
{ id: 1, name: "Ruslan", surname: "Poltayev" },
{ id: 2, name: "Handor", surname: "Ten" }
];
<小时/>
<div id="page-content-wrapper"
data-ng-controller="TableShowCtrl as t">
<select data-ng-model="t.selectedUser"
data-ng-options="item.name for item in t.userDatas track by item.id">
</select>
</div>
<小时/>
I have this results
最佳答案
您需要声明元素以显示不同的选项。要使用 name 属性显示选项,您可以使用:
<select ng-model="selected.user">
<option ng-repeat="item in t.userDatas">{{ item.name }}</option>
</select>
<!-- display selected user -->
{{ t.selected.user | json }}
关于javascript - AngularJS ng选项不显示数据,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38823999/