Ng-options filter equal to ng-model from input

I am trying to add a conditional filter to mine ng-options. Parameters should be displayed only if the identifier from the parameter array is id from another selection input.

First one ng-options:

<select ng-model="requestDepartment" ng-options="department.DepartmentID as department.DepartmentName for department in departments" class="form-control">
    <option value="">Select</option>
</select>

The second ng-optionswith filtering:

<select ng-model="requestCategory" ng-options="category.CategorytName for category in categories | filter:{category.ParentID : requestDepartment}" class="form-control">
    <option value="">Select</option>
</select>

The second ng-optionsshould only show entries that match the ng model from the first ng-options.

The data structure is as follows:

DepartmentID: 1
DepartmentName: "IT"

ParentID: 1
CategoryName: "Sharepoint"

So, if the "IT" section is selected, I want to display only those categories that correspond parentID, in this case, "Sharepoint".

I tried filter:{category.ParentID : requestDepartment}with no luck.

Any suggestions?

Update:

I added the fiddle: http://jsfiddle.net/q53ro5sr/4/

+4
1

<select ng-model="requestCategory" 
        ng-options="category.CategoryName for category in categories | filter: { ParentID: requestDepartment }" 
        class="form-control">
      <option value="">Select</option>
</select>

Fiddle

+4

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


All Articles