我知道我可以添加这样的货币过滤器:
{{amount | currency}}
但是我正在生成动态状态,因此我正在创建内联模板。所以我想知道是否可以向我的动态状态添加货币过滤器,如下所示:
data.items.forEach(function(item, index){
if(item.type === 'yearlyAmount'){
$stateProvider.state(item.alias, {
url: '/' + item.title,
template: '<h3>This item made : ' + item.amount (CONVERT item.amount TO CURRENCY) + '</h3>'
}
}
}
这可能吗?
最佳答案
是的,这是可能的。将 $filter
引用到您的模块依赖项,然后执行 $filter('currency')(item.amount)
。
或者您可以将过滤器存储在某个变量中,例如 letcurrencyFilter = $filter('currency');
并在以下情况下将其用作 currencyFilter(item.amount)
需要。
关于javascript - 我可以在 $stateProvider.state 模板中添加 Angular 过滤器吗?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/47147365/