在angularjs中未定义Toastr

use*_*165 13 jquery undefined angularjs toastr

我正在做教程,这部分是关于实现登录,这应该给出关于登录成功的气球

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

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

我得到了这个,我不明白它.似乎加载了所有.js文件.请告诉我问题出在哪里,谢谢.

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
Run Code Online (Sandbox Code Playgroud)

Phi*_*ice 19

查看toastr源代码,它看起来像getOptions()调用jQuery的$.extend()方法.

从github自述文件的第一行开始,Toastr依赖于jQuery:

toastr是一个用于非阻塞通知的Javascript库.jQuery是必需的.目标是创建一个可以自定义和扩展的简单核心库.

只需在主视图html中包含jquery即可.

<script src="http://code.jquery.com/jquery-1.11.0.min.js"></script>
Run Code Online (Sandbox Code Playgroud)

  • 这对我没什么影响.我在toastr.js之前引入了jQuery,它仍然无效.Angular只是不喜欢它. (3认同)
  • 非常感谢你,你是对的.我有jquery,我知道,但路径错了.我有`jquery/jquery.js`但我应该有`jquery/dist/jquery.js` @phil (2认同)