javascript - Filtering ngOptions by properties of an attribute -
i have code:
//sample of data. var combobox = new[] { new { key = 1, value = "a[del]", isdelegate = true }, new { key = 2, value = "b[del]", isdelegate = true }, new { key = 3, value = "c", isdelegate = false }, new { key = 4, value = "d", isdelegate = false }, new { key = 5, value = "e[del]", isdelegate = true } }; <select ng-model="selectedfilter" id="selectedfilter" ng-options="item.key item.value item in combobox track item.key" ng-change="loaddata()"> <option>--</option> </select>
i'm trying add together ng-if
options result this:
<select ng-model="selectedfilter" id="selectedfilter" ng-options="item.key item.value item in combobox track item.key" ng-change="loaddata()"> <option value="item.key" ng-if="item.isdelegate">{{item.value}}</option> </select>
you can utilize filter
class="snippet-code-js lang-js prettyprint-override">var app = angular.module('my-app', [], function() { }) app.controller('appcontroller', function($scope) { $scope.condition = { isdelegate: true } $scope.combobox = [{ key: 1, value: "a[del]", isdelegate: true }, { key: 2, value: "b[del]", isdelegate: true }, { key: 3, value: "c", isdelegate: false }, { key: 4, value: "d", isdelegate: false }, { key: 5, value: "e[del]", isdelegate: true }]; })
class="snippet-code-html lang-html prettyprint-override"><script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.2.23/angular.min.js"></script> <div ng-app="my-app" ng-controller="appcontroller"> <select ng-model="selectedfilter" id="selectedfilter" ng-options="item.key item.value item in combobox | filter:condition track item.key" ng-change="loaddata()"> <option value="item.key" ng-if="item.isdelegate">{{item.value}}</option> </select> </div>
javascript angularjs
No comments:
Post a Comment