我想知道是否可以执行以下操作:
<div ng-repeat='article in articles | filter:search'>
...
<div>
{{marked(article.body)}}
</div>
...
</div>
所以我想执行“标记”功能,将文章正文作为参数传递并显示生成的输出。
我想知道是否可以执行以下操作:
<div ng-repeat='article in articles | filter:search'>
...
<div>
{{marked(article.body)}}
</div>
...
</div>
所以我想执行“标记”功能,将文章正文作为参数传递并显示生成的输出。
当然,语法没问题! :)
你所需要的只是做到了 marked
功能是 在合适的范围内定义。
例如,让我们假设你在 ArticleCtrl
控制器:
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) }}
在你的模板。
当然,语法没问题! :)
你所需要的只是做到了 marked
功能是 在合适的范围内定义。
例如,让我们假设你在 ArticleCtrl
控制器:
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) }}
在你的模板。
它是可能的,但要确保该函数将是$ scope函数。
当然,ng-repeat中的调用函数不是一个好主意,尝试重新考虑一下你的架构,并为它创建一些模型。