JanStevens / angular-growl-2

growl-like notifications for angularJS projects
MIT License
285 stars 97 forks source link

Error: undefined is not an object (evaluating 'directive.messages') #62

Closed tlvince closed 9 years ago

tlvince commented 9 years ago

Any idea what's going on here? plunkr.

addMessage@https://raw.githubusercontent.com/JanStevens/angular-growl-2/master/build/angular-growl.js:315:31
broadcastMessage@https://raw.githubusercontent.com/JanStevens/angular-growl-2/master/build/angular-growl.js:193:52
sendMessage@https://raw.githubusercontent.com/JanStevens/angular-growl-2/master/build/angular-growl.js:222:32
info@https://raw.githubusercontent.com/JanStevens/angular-growl-2/master/build/angular-growl.js:231:27
http://run.plnkr.co/wEbSdNT3pnBuUoIq/app.js:4:13
invoke@https://code.angularjs.org/1.3.5/angular.js:4138:22
JanStevens commented 9 years ago

Hello,

I've edit it using my settings from the code pen examples. It seems that there is a bug (or not dont know yet) that you should use the growls as an action or result of something.

http://plnkr.co/edit/SLWeLg8gOzXWodatWng3?p=preview

I've added a button that can be clicked and this toggles a growl notification. I dont know in what usecase you should instantly show a growl when the controller is initialized (something odd happens then). I can look into it

tlvince commented 9 years ago

Yeah, my example is contrived (a reduced test case to demonstrate the bug), though I'll frequently trigger a growl from a service (i.e. not from a user-facing interaction) e.g. when an XHR call has failed.

punund commented 9 years ago

+1, I am seeing this too.

boxfrommars commented 9 years ago

same error

TypeError: Cannot read property 'messages' of undefined
    at addMessage (angular-growl.js:298)
    at broadcastMessage (angular-growl.js:193)
    at sendMessage (angular-growl.js:222)
    at Object.success (angular-growl.js:234)
    at regionView.js:52
    at processQueue (angular.js:13075)
    at angular.js:13091
    at Scope.$get.Scope.$eval (angular.js:14291)
    at Scope.$get.Scope.$digest (angular.js:14107)
    at Scope.$get.Scope.$apply (angular.js:14395)
JanStevens commented 9 years ago

I think this is a loading issue or async issue, it works with a button or a server response, I'll look into it this week

nathasm commented 9 years ago

I've run in to this issue when unit testing my code that calls the growlMessages service without the directive.

Essentially initDirective is never called so this.directives[referenceId] is undefined.

In my unit tests I had to do something like:

beforeEach(inject(function ($injector) {
  var $compile = $injector.get('$compile');
  var element = angular.element('<div growl></div>');
  $compile(element)($scope);
}));
gmhenderson commented 9 years ago

+1, running into this as well.

noahkeitel commented 9 years ago

+1 I'm getting this error too.

callicles commented 9 years ago

+1 ran into this while unit testing too

preston commented 9 years ago

+1