下面的代碼和一切正常加載,除非它不選擇默認選項。ng-options選擇不與對象作爲模型一起使用[Angular 1.5]
而且,option.groupJID
下拉項目價值的確實與MyCtrl.groupJID = [email protected]
<select id="groups-list2" ng-model="MyCtrl.groupJID"
ng-options="option.groupJID as option.profile.name for option in MyCtrl.userGroups track by option.groupJID">
</select>
匹配請檢查
功能:
SomeNetworkCall.then(function(success){
MyCtrl.groupJID = success.peer; //'[email protected]'
MyCtrl.userGroups = success.groups;
});
success.groups:
[
{
"groupJID": "[email protected]",
"profile": {
"name": "Flock Desktop Dev - QA issues",
"description": "QA/Dev Channel"
}
},
{
"groupJID": "[email protected]",
"profile": {
"name": "Some group name",
"description": "awesome Channel"
}
}
{
"groupJID": "[email protected]",
"profile": {
"name": "Flock Desktop 1",
"description": "QA/Dev Channel"
}
},
{
"groupJID": "[email protected]",
"profile": {
"name": "Flock Desktop 2",
"description": "QA/Dev Channel"
}
}
]
你試圖傳遞一個對象在NG-模式,而是如果一個靜態值?例如:{text:「text」,value:「value」},因爲ng-options在ng模型中給你一個對象,或者檢查你在ng-model中接收的值並傳遞該對象。 –
@DevanshiParikh ng-model是通過http調用接收的對象MyCtrl.groupJID,對於MyCtrl.userGroups也是如此。兩者都從1成功功能的服務器接收數據 – STEEL
您可以添加示例數據爲MyCtrl.groupJID和MyCtrl.userGroups –