My select box is in ng-repeat as,
<tr ng-repeat="project in projects | filter:filter">
<td>
<select class="form-control" ng-model="project.roleIds" ng-options= "role.id as role.name for role in roleList " multiple></select>
</td>
<td>
<select class="form-control" ng-model="project.company" ng-options= "obj.id as obj.name for obj in compnayList | filter:{roleId:project.roleIds}"></select>
</td>
</tr>
My roleId selection is multiple so I want to filter the company list dropdown on selection of the roles . so if I select two roles then company having anyone of the role will be there in the dropdown . Now if I select only one role then it is filtered by it but not for multiple role. Can I do such in ng-options by angular filter . Custom filter will work ?
$scope.companyList=[{
id:1,
name:"ABC",
roleId:1
},
{
id:2,
name:"ABCd",
roleId:2
},
{
id:3,
name:"ABCgh",
roleId:1
}];
$scope.roleList=[{
id:1,
name:"Grade A",
},
{
id:2,
name:"Grade B",
},
{
id:3,
name:"Grade C",
}];
And Project list is something like this,
$scope.projects=[{
id:100,
projectName:"Project 1",
roleIds: [1,2],
company:1
},
....
];
check here how you can use filter http://dojo.telerik.com/EmoQu
<input type='text' ng-model='roleId' placeholder='role id'>
<select class="form-control" ng-model="project.available" ng-options= 'obj.id as obj.name for obj in [{id:1,name:"ABC",roleId:1}, {id:2,name:"ABCd",roleId:2},{id:3,name:"ABCgh",roleId:1}] | filter:roleId'
Considering your projects array is there.
Use comparator :
$scope.in = function (items, value) {
return items.indexOf(value) !== -1;
};
In html:
<select class="form-control" ng-model="project.available"
ng-options="obj.id as obj.name for obj in compnayList | filter:{roleId:project.roleIds}:in">
</select>
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.