13

I am doing tutorial and this part is about implementing login and this should give baloons about login success

angular.module("app").value("mvToastr", toastr);

angular.module("app").factory("mvNotifier", function(mvToastr) {
   return {
      notify: function(msg) {
          mvToastr.success(msg);
          console.log(msg);
       }
    }
});

I am getting this and I don't understand it a bit. All .js files seem to be loaded. Please tell me where is the problem, thank you.

TypeError: Cannot call method 'extend' of undefined
   at getOptions (http://localhost:3030/vendor/toastr/toastr.js:282:14)
   at Object.success (http://localhost:3030/vendor/toastr/toastr.js:68:17)
   at Object.notify (http://localhost:3030/app/common/mvNotifier.js:6:22)
   at http://localhost:3030/app/account/mvNavBarLoginCtrl.js:8:28
   at wrappedCallback (http://localhost:3030/vendor/angular/angular.js:11033:81)
   at wrappedCallback (http://localhost:3030/vendor/angular/angular.js:11033:81)
   at http://localhost:3030/vendor/angular/angular.js:11119:26
   at Scope.$eval (http://localhost:3030/vendor/angular/angular.js:12045:28)
   at Scope.$digest (http://localhost:3030/vendor/angular/angular.js:11871:31)
   at Scope.$apply (http://localhost:3030/vendor/angular/angular.js:12151:24)

   angular.js:9503
Phil Price
  • 2,283
  • 20
  • 22
user3123165
  • 363
  • 1
  • 3
  • 10
  • it's pluralsight premium http://pluralsight.com/training/Courses/TableOfContents/building-angularjs-nodejs-apps-mean - Improving the Client Login Code – user3123165 Mar 05 '14 at 23:03
  • Congrats, your question helped me implement toastr as an Angular service. Thanks! – iulial Jul 14 '17 at 11:29

3 Answers3

19

Looking at the toastr sources it looks like getOptions() calls jQuery's $.extend() method.

Toastr takes a dependency on jQuery, from the first line of the github readme:

toastr is a Javascript library for non-blocking notifications. jQuery is required. The goal is to create a simple core library that can be customized and extended.

Just include jquery in your master view html.

<script src="http://code.jquery.com/jquery-1.11.0.min.js"></script>
Phil Price
  • 2,283
  • 20
  • 22
  • 2
    thank you so much, you are right. I had jquery and i knew it, but the path was wrong. i had `jquery/jquery.js` but i should have `jquery/dist/jquery.js` @phil – user3123165 Mar 06 '14 at 10:37
  • 3
    This makes no difference to me. I pull in jQuery before toastr.js and it still doesn't work. Angular just doesn't like it. – Arminder Dahul Dec 05 '14 at 12:46
  • @ArminderDahul late reply I know, but toastr *does* work fine with angular. You should include jquery *before* angular, otherwise angular will essentially overwrite jquery with its own "jqlite" implementation. https://docs.angularjs.org/misc/faq#does-angular-use-the-jquery-library- – Zach Lysobey Oct 02 '15 at 16:45
1

I had this problem and it turns out Toastr needs JQuery to work, always make sure you include JQuery before Toastr, for example in angular.json:

            "scripts": [
              "node_modules/jquery/dist/jquery.min.js", // Make sure this comes before
              "node_modules/toastr/build/toastr.min.js", // this one
              "node_modules/bootstrap/dist/js/bootstrap.min.js"
            ]
Yidir
  • 583
  • 7
  • 12
0

I had this problem working with automated tasks and then loading up in browser. I upgraded browser-sync and it fixed it.

Post Impatica
  • 14,999
  • 9
  • 67
  • 78