我正在尝试将ng-rollbar添加到我的RoR+AngularJS项目中。堆栈是:Ruby2.3.1p112、Rails 4.2.6和angularJS 1.4.12。按照指示运行命令:
bower安装ng-rollbar -保存
下面是我的bower.json:
{
"name": "dsl-generated dependencies",
"dependencies": {
"foundation-sites": "~6.2.3",
"jquery-ujs": "~1.2.1",
"angular": "~1.4.12",
"angular-sanitize": "~1.4.12",
"angular-cookies": "~1.4.12",
"angular-route": "~1.4.12",
"angular-resource": "~1.4.12",
"angular-local-storage": "~0.2.7",
"angular-scroll-glue": "~2.0.7",
"components-font-awesome": "~4.6.3",
"pusher": "~3.1.0",
"pusher-angular": "~0.1.9",
"angular-payments": "git://github.com/laurihy/angular-payments#9643191f23",
"angular-moment": "~0.10.3",
"angular-xeditable": "~0.2.0",
"zInfiniteScroll": "~1.1.4",
"motion-ui": "~1.2.2",
"angular-toastr": "~1.7.0",
"angular-elastic": "~2.5.1",
"angular-material": "~1.0.9",
"angular-google-analytics": "~1.1.7",
"angular-animate": "~1.4.12",
"angular-aria": "~1.4.12",
"angular-messages": "~1.4.12",
"ng-rollbar": "^1.9.2"
},
"resolutions": {
"angular": "~1.4.12"
}}
然后,我创建了一个名为app/assets/javascripts/config/ngrolbar.js的文件,在该文件中,rollbar被初始化:
app.config(function(ngRollbarProvider) {
RollbarProvider.init({
accessToken: "<MY-APPLICATION-TOKEN>",
captureUncaught: true,
payload: {
environment: 'production'
}
});
});并在app/assets/javascripts/config/app.js中添加了ngrollbar:
var app = angular.module('chat',
[
'pusher-angular',`enter code here`
'luegg.directives',
'ngRoute',
'templates',
'angularPayments',
'angularMoment',
'xeditable',
'zInfiniteScroll',
'toastr',
'monospaced.elastic',
'ngMaterial',
'angular-google-analytics',
'tandibar/ng-rollbar',
]).run( ["$rootScope","$http","amMoment","editableOptions","editableThemes","$mdSidenav",'Analytics','ngrollbar', function($rootScope , $http , amMoment , editableOptions , editableThemes , $mdSidenav , Analytics , ngrollbar) { ... }]);在app/assets/javascripts/controllers/chat.js中:
app.controller("ChatController", [$scope","$rootScope","$http",'$pusher','$location','$routeParams','userProfile','toastr','flash','ngrollbar', function($scope , $rootScope , $http , $pusher , $location , $routeParams , userProfile , toastr , flash , ngrollbar ) {...}]);在app/assets/javascripts/application.js中,我添加了://= require ng-rollbar
当我尝试运行我的应用程序时,我在浏览器控制台中得到以下消息:
Error: [$injector:modulerr] Failed to instantiate module chat due to:
[$injector:unpr] Unknown provider: ngRollbarProvider我很确定这不是ng-rollbar的一个具体问题,在向我的RoR+AngularJS应用程序中添加一个新模块的过程中,我遗漏了一些步骤,但是我不知道我做错了什么。我已经检查了之前涉及这个错误的任何问题,但是我找不到任何涉及使用angularJS和Rails的问题。
发布于 2017-04-10 12:23:25
一个月后,我问了问题的部分回购,我得到了一个难以置信的快速答案:https://github.com/tandibar/ng-rollbar/issues/30
这只是命名上的混乱:您必须注入“Rollbar”而不是“ngrollbar”。
app.controller("ChatController", [$scope","$rootScope","$http",'$pusher','$location','$routeParams','userProfile','toastr','flash','Rollbar', function($scope , $rootScope , $http , $pusher , $location , $routeParams , userProfile , toastr , flash , Rollbar ) {...}]);在将一些ng-rollbar和ngRollbar更改为Rollbar之后,一切都变得很有魅力了。
https://stackoverflow.com/questions/42717334
复制相似问题