3

これがディレクティブです

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();'>&times;</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 はトリガーされません

4

1 に答える 1