问题
I am trying to apply a filter on a parameter in my ui-sref
reference.
<a ui-sref="item.show({ itemId: item.id, itemName: item.name | slugify })">
However, the above is not working. How to I apply the slugify
filter to item.name
?
回答1:
You can use a function:
<a ui-sref="item.show({ itemId: item.id, itemName: getSlugifiedName(item) })">
And in your controller, something like that:
$scope.getSlugifiedName = function (item) {
return $filter('slugify')(item.name);
}
回答2:
Use parentheses for filter:
<a ui-sref="item.show({ itemId: item.id, itemName: (item.name | slugify) })">
来源:https://stackoverflow.com/questions/23494358/filter-in-ui-sref