我试图在一个ngSelected中自动选择一个使用ngRepeat。
其中一个选项在生成的html中和标记之间有" selected“属性,但该选项似乎没有选定的选项。
$scope.selected = 2;
$scope.isSelected = function(x) {
return (x == $scope.selected);
};
$scope.myList = [{
"id": "1", "name": "aaa"
}, {
"id": "2", "name": "bbb"
}, {
"id": "3", "name": "xxx"
}];
..。
<select ng-model="selected">
<option ng-repeat="item in myList" value="{{item.id}}"
ng-selected="isSelected(item.id)">
{{item.name}} [selected {{item.id == selected}}]</option>
</select>
我尝试过parseInt值,把它们转换成字符串,比较.但这是一样的:显然,没有选择。
https://jsfiddle.net/monguz/yxsqgz5n/
我遗漏了什么?谢谢
编辑:感谢您的评论和回复。
小提琴显示了我的真实代码的一个简化版本。我已经尝试过“选择”作为字符串,但我不能100%确定它的类型。
无论如何,我不明白为什么代码as-is没有显示所选的选项。根据docs,表达式是“真实的”,因此它应该以选定的形式出现。
发布于 2016-03-30 12:56:39
为了这个我改变了主意然后工作了。
$scope.selected = '2';
https://stackoverflow.com/questions/36319149
复制