Search code examples
javascriptangularjsangular-filters

Pass variable into Angular filter


I'm writing an Angular app with some dynamic pages. I've got a stateParam named currentCategory which gives back an integer for current category's id. Is there a way to pass this integer into an Angular filter, since I only want to show current page's category?

This would be straightforward, but returns an syntax error.

<div ng-repeat="category in categories | filter:{cat_id:{{currentCategory}}}:true">


Solution

  • Remove the interpolate expressions ({{ }}) and it should work:

    filter:{cat_id:currentCategory}:true