我想知道是否可以执行以下操作:
<div ng-repeat='article in articles | filter:search'>
...
<div>
{{marked(article.body)}}
</div>
...
</div>
所以我想执行“标记”函数,将文章正文作为参数传递并显示生成的输出。
最佳答案
当然,那个语法没问题! :)
您所需要的只是确保您收到 marked
功能是 定义在正确的范围内 .
例如,假设您在 ArticleCtrl
Controller :
app.controller('ArticleCtrl', function($scope) {
// Declare the method in the controller's scope
$scope.marked = function(article_body) {
// do whatever you want here
// and don't forget to return the expected result
return "LOVE CAPS! " + article_body.toUpperCase();
};
});
然后您可以使用
{{ marked(something) }}
在你的模板中。
关于angularjs - Angular,从函数输出到表达式,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25719870/