【发布时间】:2013-11-30 07:11:28
【问题描述】:
我正在使用 Angularjs 开发一个应用程序,并在我的页面中使用 $sce.trustAsHtml() 添加 HTML。我想在上面动态添加的内容中调用一个函数。我的html和脚本如下。
HTML
<div ng-app="ngBindHtmlExample">
<div ng-controller="ngBindHtmlCtrl">
<p ng-bind-html="myHTML"></p>
</div>
</div>
Javascript
angular.module('ngBindHtmlExample', ['ngSanitize'])
.controller('ngBindHtmlCtrl', ['$scope','$sce', function ngBindHtmlCtrl($scope, $sce) {
$scope.myHTML =$sce.trustAsHtml(
'I am an <code>HTML</code>string with <a href="#" ng-mouseover="removeExp()">links!</a> and other <em>stuff</em>');
$scope.removeExp = function (){
console.log('dfdfgdfgdfg');
}
}]);
jsfiddle
【问题讨论】:
标签: javascript angularjs