这是指令
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;
}
};
});
在控制器中,我将链接放入 msg var
msg = msg.replace("[", "<a href='javascript:return false' ng-click='alert()'>");
msg = msg.replace("]", "</a>");
但是 ng-click 没有被触发 有人吗?