是否可以正确删除空白值选择** ng repeat **

时间:2017-07-15 11:40:03

标签: angularjs

我对AngularJS Guru感到愤怒。是否有可能从下一个列表中删除空白值,其中klassList是一些对象列表。我需要  完全ng-repeat 而非 ng-options [{"id":1,"klassName":"11A","pupils":null},{"id":2,"klassName":"12B","pupils":null}]

<input type="text" class="form-control" ng-model="klassName1"/>
<select class="form-control" ng-model="selectedItem" >
    <option ng-repeat="klass in klassList | filter :  {klassName : klassName1}">{{klass.klassName}}</option>
</select>

我的目标是获取可能过滤值的下拉列表。

1 个答案:

答案 0 :(得分:0)

使用 ng-options

ng-options="givendata as givendata .klassName for givendata in klassList"

angular.module('app', []).controller('SelectorCtrl', function($scope) {
  $scope.klassList  = [{"id":1,"klassName":"11A","pupils":null},{"id":2,"klassName":"12B","pupils":null}];
});
<!DOCTYPE html>
<html ng-app="app">
<head>
  <script data-require="angular.js@1.4.3" data-semver="1.4.3" src="https://code.angularjs.org/1.4.3/angular.js"></script>
  <link rel="stylesheet" href="style.css" />
  <script src="script.js"></script>
</head>
<body ng-controller="SelectorCtrl">
  <h1>Hello!</h1>
  <select class="form-control"  ng-model="selectedItem" id="state" ng-model="divisionsSource" ng-options="givendata  as givendata.klassName for givendata in klassList">
    <option value=''>Select</option>
  </select>
  
</body>
</html>