简体   繁体   English

将变量传递到角度过滤器

[英]Pass variable into Angular filter

I'm writing an Angular app with some dynamic pages. 我正在编写带有一些动态页面的Angular应用程序。 I've got a stateParam named currentCategory which gives back an integer for current category's id. 我有一个名为currentCategorystateParam ,它为当前类别的ID返回一个整数。 Is there a way to pass this integer into an Angular filter, since I only want to show current page's category? 因为我只想显示当前页面的类别,有没有办法将此整数传递给Angular过滤器?

This would be straightforward, but returns an syntax error. 这很简单,但是返回语法错误。

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

删除插值表达式( {{ }} ),它应该可以工作:

filter:{cat_id:currentCategory}:true

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM