cgross / angular-notify

Minimalistic and extensible notification service for Angular.

Home Page:http://cgross.github.io/angular-notify/demo/

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Allow .cg-notify-message-template in elements not in the imediate child list

SuricateCan opened this issue · comments

I ran into this recently. Currently, if the element containing .cg-notify-message-template is not a child of the root element in the template, cgNotify throws an error: "cgNotify could not find the .cg-notify-message-template element in..."

To work around it is pretty simple, and I wrote a code to do so.
Just replace lines 43-49 in angular-notify.js:

                    var messageTemplateElement;
                    for (var i = 0; i < templateElement.children().length; i ++){
                        if (angular.element(templateElement.children()[i]).hasClass('cg-notify-message-template')){
                            messageTemplateElement = angular.element(templateElement.children()[i]);
                            break;
                        }
                    }

with this:

                    var fnRecursiveLook = function (myElement) {
                        var children = myElement.children();
                        for (var i = 0; i < children.length; i++) {
                            var child = angular.element(children[i]);
                            if (child.hasClass('cg-notify-message-template')) {
                                return child;
                            }
                            if (child.children().length > 0) {
                                return fnRecursiveLook(child);
                            }
                        }
                        return undefined;
                    };
                    var messageTemplateElement = fnRecursiveLook(templateElement);