ng 模型不适用于选择
ng-model not working with select
这可能是
一个重复的问题,但是在将另一个数组绑定到下拉列表时,我在显示数据中的默认值时遇到了困难。列表已填充,但加载后应显示的选定值未显示。
这是我的示例代码:
.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: 下拉问题 - Angularjs
代码对我来说
似乎很好,但是您将 subscription.subscribeAddresses.ChannelAddress 初始化为"yad_ajay@ts.com"。我在您的通讯信息中没有看到任何 yad_ajay@ts.com。猜猜这就是问题。
编辑:这是您的弹跳机的工作选择
<select class="form-control right"
ng-if="subscription.subscribedAddresses.DeliveryChannel=='EMAIL'"
ng-model="subscription.subscribedAddresses"
ng-options="channel as channel.ChannelAddress for channel in commInfo.emails track by channel.ChannelAddressId"
required>
</select>
更改:在 ng-if 中将通道类型更改为交付
更改 ng 选项添加跟踪以帮助角度识别对象的单一性
工作普伦克 :-http://plnkr.co/edit/LSbJ2RVRw9zJleSwP3YT?p=preview
ng-model 不适合 commInfo 列表中的任何模型。这是您的解决方案。
[Jsfiddle](https://jsfiddle.net/6b3ntn73/28/)
相关文章:
- JQueryhide()不适用于Mozzilla,但适用于Chrome
- PHP中的setcookie仅适用于localhost
- html5 drawImage适用于firefox,而不是chrome
- 提供“;onClick"适用于iPad(触摸屏)和桌面用户的默认功能
- jQuery表单验证适用于Mozilla和Internet Explorer,但不适用于Chrome或Safari
- ResolveUrl是否适用于././也
- Firebase updateChildValues适用于IOS,但不适用于Web和Android
- JavaScript警报适用于int,但不适用于string
- SQLite插件适用于Mac和Windows,但不适用于手机上的Safari
- Regex Replace仅适用于Last Match
- window.onload适用于aspx页面,但不适用于普通html
- Jquery Ajax POST不工作.适用于GET
- 动态选择列表上的单击事件仅适用于 FF
- html 选择列表更改无法在谷歌浏览器上调用方法(适用于 IE)
- 未在火狐浏览器的选择列表中选择值(适用于chrome,safari,opera)
- XPath选择不适用于Microsoft Edge(适用于Chrome和Firefox)
- JQuery日期选择器不适用于IE,适用于Firefox和Chrome
- jQuery选择菜单验证器适用于FF和Chrome,但不适用IE
- SVG元素的矩形选择(适用于Raphael)
- 无法从下拉菜单中选择firefox(适用于Chrome)