[英]ng-click won't work with ng-bind-html
我有像这样的html模板:
$scope.template = '<span class="pointer"><i class="icon-refresh pointer" ng-click="refresh()"></i></span>';
我想使用ng-bind-html
绑定这个模板,我试图使用它,我也使用了ng-bind-html-unsafe
,但不幸的是它绑定了html字符串,因为没有点击动作。
<span ng-bind-html="template"></span>
<span ng-bind-html-unsafe="template"></span>
我读到了类似的问题,它说ng-click
是在ng-bind
之后加载的,所以有人可以向我介绍如何解决这个问题吗?
也许您需要在控制器内编译模板?
angular.controller('ABCDCtrl', function($scope, $compile){
var templateHTML = '<span class="pointer"><i class="icon-refresh pointer" ng-click="refresh()"></i></span>';
$scope.template = $compile(templateHTML)($scope);
});
您可以尝试使用ng-include并将模板放入静态文件中。
我认为,将HTML内容放在范围变量中会违背一些有棱角的哲学准则。
如果您以后要更改模板,是否要重新绑定并重新处理?
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.