Angular Strap - 警告不能使用指令

时间:2015-06-05 07:46:48

标签: javascript angularjs twitter-bootstrap angular-strap

我写了指令在某个范围内显示通知: 但是,bootstrap strap(http://mgcrea.github.io/angular-strap/#/alerts)警报服务不会向我的指令容器添加警报,为什么?

  app.directive("notification", function ($alert, $rootScope) {
        return {
            restrict: "E",
            template: '<div></div>',
            link: function (scope, element) {
                var id = "#alerts-container" + getRandomId();
                element.attr("id", id);
                scope.$on('notificationEvent', function (event, alertArg) {
                    var alert = angular.extend(alertArg, {container: id});
                    console.log(alert);
                    $alert(alert);
                    event.preventDefault();
                });

            }
        };
    });

页:

<notification>
</notification>

所有事件都在处理,在notificationEvent运行时没有错误,但我的通知容器始终为空。你能帮帮我吗?

谢谢!

2 个答案:

答案 0 :(得分:1)

它看起来你设置的只是id而不是selector('#'+ id)。

答案 1 :(得分:0)

这是我的错:id - 不正确; attr(&#39; id&#39;,&#39; #id&#39;) - #...