TietjeDK TietjeDK - 1 year ago 127
AngularJS Question

ng-options filter equal to ng-model from input

I'm trying to add conditional filter to my

. The options should only be displayed when an id from the options array equals an id from a different select input.

The first

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

The second
with filtering:

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

The second
should only show entries which match the ng-model from the first

The structure for the data is as follows:

DepartmentID: 1
DepartmentName: "IT"

ParentID: 1
CategoryName: "Sharepoint"

So, if department "IT" is selected I only want to display categories that match the
, in this case "Sharepoint".

I have tried
filter:{category.ParentID : requestDepartment}
without luck.

Any suggestions?


I have added a fiddle: http://jsfiddle.net/q53ro5sr/4/

Answer Source

This should work

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

Here is a Fiddle

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download