通过$ sce.trustAsHtml呈现时访问ng-click [英] Accessing ng-click when rendered via $sce.trustAsHtml

查看:40
本文介绍了通过$ sce.trustAsHtml呈现时访问ng-click的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我如何在下面访问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屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆