相关疑难解决方法(0)

AngularJS.当select具有ng-model属性时,ng-selected不起作用

我正在尝试设置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)

angularjs angularjs-ng-model

5
推荐指数
1
解决办法
2319
查看次数

标签 统计

angularjs ×1

angularjs-ng-model ×1