我正在尝试基于名为“默认”的列表值之一来设置下拉列表的默认值。
这是下拉代码。
<div ng-app="myApp">
<div ng-controller="AppCtrl">
{{message}} <br />
<!--Options value is defualt 0, 1 ... and it's non change able -->
<span>Default Otions:</span>
<select ng-model="mail_notification"
ng-options="c.key as c.value for c in mail_notifications"
ng-selected = "c.default = 'Y'">
</select>
<br />
</div>
</div>
如果默认='Y',则设置下拉默认值
这是示例json数据。
controller('AppCtrl', function($scope){
$scope.mail_notifications = [
{
"key": "all",
"value": "For any event on all my projects",
"default":"N"
},
{
"key": "selected",
"value": "For any event on the selected projects only...",
"default":"Y"
},
{
"key": "only_my_events",
"value": "Only for things I watch or I'm involved in",
"default":"N"
}
];
AngularJS. When select have ng-model attribute, ng-selected not working 我曾尝试过此解决方案的重复问题,但此处选择的问题基于列表中的其他值。
带标记的重复问题中提供的答案是不同的。默认情况下添加了一个新的“选择项目”选项。在这里,我想根据条件添加默认值。请删除重复的问号,以提出解决方案。