Toastr 不能与 AngularJs 结合使用
Toastr not working in conjuction with AngularJs
我正在尝试将 Toastr
与 angular js
一起使用,但出现以下错误。我按预期包含了 jquery.js
文件。
src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.3/jquery.min.js"
错误信息:
angular.js:11594 TypeError: Cannot read property 'extend' of undefined
at m (toastr.js:474)
at Object.o [as info] (toastr.js:474)
at ProductTableController.showAddToCartToast (productTable.directive.js:207)
at ProductTableController.addToCart (productTable.directive.js:159)
at angular.js:12332
at f (angular.js:22949)
at a.$$ChildScope.$$ChildScope.$eval (angular.js:14383)
at a.$$ChildScope.$$ChildScope.$apply (angular.js:14482)
at HTMLButtonElement. (angular.js:22954)
at HTMLButtonElement.dispatch (jquery.js:4670)(anonymous function) @ angular.js:11594(anonymous function) @ angular.js:8544$apply @ angular.js:14484(anonymous function) @ angular.js:22954dispatch @ jquery.js:4670r.handle @ jquery.js:4338
知道哪里出了问题吗?
谢谢。
您可以改用 angular-toastr 库
安装:bower install angular-toastr
包括依赖项:angular.module('app', ['ngAnimate', 'toastr'])
在控制器中使用:
app.controller('foo', function($scope, toastr) {
toastr.success('Hello world!', 'Toastr fun!');
});
我认为您在 angular.js 之后包含了 Jquery 文件。将 Jquery 文件移到 Angularjs 文件上方。
例如
1. <script src ="jquery.min.js"></script>
2. <script src ="angular.min.js"></script>
我正在尝试将 Toastr
与 angular js
一起使用,但出现以下错误。我按预期包含了 jquery.js
文件。
src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.3/jquery.min.js"
错误信息:
angular.js:11594 TypeError: Cannot read property 'extend' of undefined
at m (toastr.js:474)
at Object.o [as info] (toastr.js:474)
at ProductTableController.showAddToCartToast (productTable.directive.js:207)
at ProductTableController.addToCart (productTable.directive.js:159)
at angular.js:12332
at f (angular.js:22949)
at a.$$ChildScope.$$ChildScope.$eval (angular.js:14383) at a.$$ChildScope.$$ChildScope.$apply (angular.js:14482) at HTMLButtonElement. (angular.js:22954) at HTMLButtonElement.dispatch (jquery.js:4670)(anonymous function) @ angular.js:11594(anonymous function) @ angular.js:8544$apply @ angular.js:14484(anonymous function) @ angular.js:22954dispatch @ jquery.js:4670r.handle @ jquery.js:4338
知道哪里出了问题吗?
谢谢。
您可以改用 angular-toastr 库
安装:bower install angular-toastr
包括依赖项:angular.module('app', ['ngAnimate', 'toastr'])
在控制器中使用:
app.controller('foo', function($scope, toastr) {
toastr.success('Hello world!', 'Toastr fun!');
});
我认为您在 angular.js 之后包含了 Jquery 文件。将 Jquery 文件移到 Angularjs 文件上方。
例如
1. <script src ="jquery.min.js"></script>
2. <script src ="angular.min.js"></script>