javascript - hide a specific ng-option if it's id already exists in array -
i have drop down adds items on page binded $scope. want make sure don't add doubles array idea ng-hide option if exists in array. don't know if it's possible because ng-options inside select dont know if can append ng-hide them in first place.
regardless, if possible, hide option if it's id exists in scope.
i thinking loop through each , check, here attempt
$scope.checkifexist = function () { var ifexist = false; angular.foreach($scope.promptsplease, function (data) { if (data.id == $scope.promptsplease.id){ ifexist = true; } }); return ifexist; };
and select in controller looks like
<select ng-model="fadingselected" ng-options="type.name type in fadingtypes track type.id" ng-hide="checkifexist()"> </select>
i don't know if possible, , think might approaching wrong. idea cannot add same 1 twice array that's binded scope. doesn't have ng-hide, nice. appreciated! reading.
this previous answer might apply problem (https://stackoverflow.com/a/19329910/1036025).
here included demo (plunker): http://plnkr.co/edit/sf3el0fyuptwq28xqzni?p=preview
it illustrates 3 ways of achieving this. 1 using library lodash
manipulate data , create filtered list of available choices instead of using angular.each
.
i recommend have @ 3rd explained option in description (alternative using filter).
Comments
Post a Comment