3
这是指令Angularjs NG-点击下不烧NG绑定,HTML不安全
aomApp.directive('aomAlert', function ($rootScope,$compile) {
return {
restrict:'EA',
transclude:true,
replace:true,
scope: {type: '=', msgCollection: '=', close: '&'},
controller: function ($scope, $element, $attrs,$compile) {
$scope.show = false;
$scope.$watch('msgCollection', function(selectedPlan) {
$scope.show = ($scope.msgCollection.length > 0);
});
},
template:
"<div class='alert' ng-class='type && \"alert-\" + type' ng-show='show'>" +
" <button ng-show='closeable' type='button' class='close' ng-click='show = false;close();'>×</button>" +
" <ul>" +
" <div ng-repeat='msg in msgCollection'><li><div ng-bind-html-unsafe=msg></div></li></div>"+
" <ul>" +
"</div>",
link: function($scope, $element, $attrs) {
$scope.closeable = "close" in $attrs;
}
};
});
和我把链接放入味精VAR
msg = msg.replace("[", "<a href='javascript:return false' ng-click='alert()'>");
msg = msg.replace("]", "</a>");
控制器然而NG单击犯规被触发 任何人?
我经历了文档,但仍然对此问题感到困惑,我尝试编译模板中的html-bind-unsafe,如下所示:
不,你必须在你的指令后做。为什么你用这种方式使用html-bind-unsafe?它通常保留给角度不属于的部分。 –
你指的是什么意思?你能给我这个代码吗?谢谢你的回复 – user2501711