如何创建,我可以用它来修改文字显示的功能? [英] How can I create a function that I could use to modify text displayed?
本文介绍了如何创建,我可以用它来修改文字显示的功能?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我用这code:
$scope.indexChar = function (index) {
return String.fromCharCode(65 + index);
};
有没有一种方法,我可以在我的应用程序做同样有着共同的功能?
Is there a way I can create a common function shared in my application to do the same?
推荐答案
您可以尝试过滤器
app.filter('indexChar', function() {
return function(index) {
return String.fromCharCode(65 + index);
};
});
- 内使用模板,像这样的语法:
{{$指数| indexChar}}
- 注入到控制器
&LT使用; FILTERNAME过滤器过滤
语法,在这种情况下是indexCharFilter
并使用它像这样:的console.log(使用控制器中:+ indexCharFilter(1));
- Use inside template with syntax like this:
{{ $index | indexChar}}
- Inject to controller to use with
<filterName>Filter
syntax, in this case isindexCharFilter
and use it like this:console.log("Use in controller:" + indexCharFilter(1));
这篇关于如何创建,我可以用它来修改文字显示的功能?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文