Angularjs 安格拉斯。选择“具有ng模型属性”时,选择的ng不工作
我正在尝试设置Angularjs 安格拉斯。选择“具有ng模型属性”时,选择的ng不工作,angularjs,angularjs-ng-model,Angularjs,Angularjs Ng Model,我正在尝试设置ng selected在我的选项元素中,selected属性设置为true,但是选项未被选中,当我从选择中删除ng model时,所有属性都变为工作状态 问题:当我使用模型时,如何选择选项 这里是(选中的不在这里工作) 我的代码: var app = angular.module("plunker", []); app.controller("TestController", ["$scope", function($scope) { $scope.test = 1; $
ng selected
在我的选项
元素中,selected
属性设置为true
,但是选项
未被选中,当我从选择
中删除ng model
时,所有属性都变为工作状态
问题:当我使用模型时,如何选择选项
这里是(选中的
不在这里工作)
我的代码:
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"}
];
}]);
我的模板:
<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 }} ({{item.id == test}})
</option>
</select>
</body>
所选项必须为{array[test-1].name}
选择项目。。
{{item.name}}({{item.id==test})
非常感谢你的帮助 不要将ngSelected与ngRepeat一起使用。选择以下选项:
<body ng-controller="TestController">
Selected item must be {{ array[test-1].name }}
<select ng-model="myModel" ng-options="item.id as item.name for item in array">
<option value="">Choose item..</option>
</select>
</body>
所选项必须为{array[test-1].name}
选择项目。。
不要将ngSelected
与ngModel
从文档中:
注意:ngSelected
不与
和ngModel
指令交互,它只在元素上设置所选属性。如果在选择上使用ngModel
,则不应在选项上使用ngSelected
,因为ngModel
将设置选择值和所选选项
请参阅其他文档: