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