Filter values ​​dynamically with select using angular js

I have a choice where I fill in certain values, as shown below:

Values:

     $scope.obj = {codes: [
        {code: 1},
        {code: 2},
        {code: 3}
     ]};

Now I want to dynamically filter certain values ​​without making any changes to the value of $ scope.obj, that is, I do not want to display the value of {code: 1}. I set this value in another variable in the $ scope:

$ scope.selectedCode = {code: 1};

All values ​​present in the selected code should not be displayed in the drop-down list. I think this can be done using the angular js filter expression:

<select ng-options="c.code for c in obj.codes | filter:'c.code !== selectedCode .code'" ng-model="selected">

But the above shows an empty snapshot.

Any help / guidance is appreciated. Thanks in advance.:)

+4
source share
2

:

$scope.filterCodes = function(obj) {
    return obj.code !== $scope.selectedCode.code;
};

:

<select ng-options="c.code for c in obj.codes | filter:filterCodes" ng-model="selected"></select>

UPD. :

ng-options="c.code for c in obj.codes | filter: '!' + selectedCode.code"
+6

Tyr , .

<select ng-options="c.code for c in filteredobj = (obj.codes | filter:'code':'!'+ selectedCode.code)" ng-model="selected">
0

Source: https://habr.com/ru/post/1569860/


All Articles