通过$ sce.trustAsHtml呈现时访问ng-click [英] Accessing ng-click when rendered via $sce.trustAsHtml
问题描述
我如何在下面访问ng-click函数(updateRating)?
How do i get access to the ng-click function (updateRating) in the below?
https://jsfiddle.net/by2jax5v/171/
我正在使用$ sce.trustAsHtml渲染$ scope.content
I'm using $sce.trustAsHtml to render $scope.content
$scope.bindHTML = $sce.trustAsHtml($scope.content);
推荐答案
您的上述代码确实得到编译,但是考虑到锚标记不安全,Angular js对其进行了清理,因此ng-click无效.
Your above code does get compiled but it is sanitized by angular js considering an anchor tag as insecure, therefore ng-click does not work.
要实现的目标可以通过使用francis bouvier的ng-html-compile
代替ng-bind-html
来实现.它是我见过的最薄的库,只有1kb. https://github.com/francisbouvier/ng_html_compile
what you want to achieve can be achieved by using ng-html-compile
by francis bouvier instead of ng-bind-html
. It the thinnest library i have seen just 1kb. https://github.com/francisbouvier/ng_html_compile
另请参阅 https://stackoverflow.com/a/41790235
这篇关于通过$ sce.trustAsHtml呈现时访问ng-click的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!