我正在尝试将ng-rollbar添加到我的RoR + AngularJS项目中。堆栈是:ruby 2.3.1p112,Rails 4.2.6和angularJS 1.4.12。 按照说明运行命令:
bower安装ng-rollbar --save
之后是我的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 / ngrollbar.js的文件,其中rollbar获得了initiallize:
app.config(function(ngRollbarProvider) {
RollbarProvider.init({
accessToken: "<MY-APPLICATION-TOKEN>",
captureUncaught: true,
payload: {
environment: 'production'
}
});
});
并将ngrollbar添加到app / assets / javascripts / config / app.js:
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和Ruby On Rails的人。
答案 0 :(得分:0)
一个月之后,我在回购的问题部分询问了我得到了一个非常快的回答: https://github.com/tandibar/ng-rollbar/issues/30
这只是一个命名混乱:你必须注入&#39; Rollbar&#39;而不是&#39; ngrollbar&#39;。
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后,一切都像魅力一样。