我正在尝试设置ng-selected我的option元素,selected属性设置为true,但未option选中,当我ng-model从中删除后select变得有效.
问题:option当我使用模型时如何选择?
这是我的plunker(selected不在这里工作)
我的代码:
var app = angular.module("plunker", []);
app.controller("TestController", ["$scope", function($scope) {
$scope.test = 1;
$scope.array = [
{"id": 1, "name": "first"},
{"id": 2, "name": "second"},
{"id": 3, "name": "third"}
];
}]);
Run Code Online (Sandbox Code Playgroud)
我的模板:
<body ng-controller="TestController">
Selected item must be {{ array[test-1].name }}
<select ng-model="myModel">
<option value="">Choose item..</option>
<option ng-repeat="item in array"
ng-value="item.id"
ng-selected="item.id == test">
{{ item.name }} …Run Code Online (Sandbox Code Playgroud)