【发布时间】:2023-03-05 22:29:02
【问题描述】:
这可能是一个重复的问题,但在将另一个数组绑定到下拉列表时显示我的数据中的默认值时我被卡住了。列表已填充,但加载后应显示的选定值未显示。
这是我的示例代码:
HTML:
<div ng-app="app">
<div ng-controller="myCntrl">
<select class="form-control right"
ng-if="subscription.subscribedAddresses.ChannelType=='EMAIL'"
ng-model="subscription.subscribedAddresses.ChannelAddress"
ng-options="channel.ChannelAddress for channel in commInfo.emails track by channel.ChannelAddress" required>
</select>
</div>
JS:
angular.module('app', [])
.controller('myCntrl', ['$scope', function($scope) {
$scope.commInfo = {
"emails": [{
"ChannelAddressId": 5000054652,
"DeliveryChannel": "EMAIL",
"ChannelType": null,
"ChannelAddress": "ya_ajay@net.com"
}, {
"ChannelAddressId": 5000075277,
"DeliveryChannel": "EMAIL",
"ChannelType": null,
"ChannelAddress": "yad_ay@ts.com"
}, {
"ChannelAddressId": 5000075278,
"DeliveryChannel": "EMAIL",
"ChannelType": null,
"ChannelAddress": "yadav_aaj@gmail.com"
}, {
"ChannelAddressId": 5000075279,
"DeliveryChannel": "EMAIL",
"ChannelType": "UNKNOWN",
"ChannelAddress": "test_ay@mail.com"
}],
"phones": [{
"ChannelAddressId": 5000075390,
"DeliveryChannel": "PHON",
"ChannelType": "UNKNOWN",
"ChannelAddress": "4561237895"
}, {
"ChannelAddressId": 5000075397,
"DeliveryChannel": "PHON",
"ChannelType": "UNKNOWN",
"ChannelAddress": "7894561236"
}]
};
$scope.subscription = {"serviceName":"RAM Month","subscribedAddresses":{"ChannelAddress":"yad_ajay@ts.com","ChannelType":"EMAIL"}};
}]);
这是 Plunkr: Plunkr: Dropdown issue - Angularjs
【问题讨论】:
标签: javascript angularjs angularjs-scope angularjs-ng-repeat html-select