0

i have the following arry in my scope

 items: [
{
id: "0",
name: "כיבוי אורות",
roomId: "0",
type: "scenario",
status: 1
},
{
id: "1",
name: "הדלקת אורות",
roomId: "0",
type: "scenario",
status: 1
},
{
id: "0",
name: "תנור מטבח",
roomId: "0",
type: "heater",
status: 0
}]

i would like to filter it by id and type within the controller ( not by ng-repeat | filter).

Thanks allot

Avi

0

1 Answer 1

1

Well if you want to filter by name and id from within the controller you could just use native filter. Look at the polyfill for support for older browsers.

var type = "TypeTOfilter",  id=idToFilter;
$scope.items = items.filter(function(itm){ return itm.id === id && itm.type === type  });

Or you could even inject ``$filter` in your controller, if you just want to do it one time, and not have it in the ng-repeat.

.controller('ctrl', ['$scope', 'filterFilter', function($scope, filter){
     //...
     $scope.items = filter(items)({type:type, id:id});
     //....
 }]);

Or you could even do a for-loop to filter out items..

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.