0

我正在尝试将 ng-rollbar 添加到我的 RoR+AngularJS 项目中。堆栈是:ruby 2.3.1p112、Rails 4.2.6 和 angularJS 1.4.12。按照说明我运行了命令:

凉亭安装 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 的文件,其中滚动条被初始化:

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 的人。

4

1 回答 1

0

一个月后,我在回购的问题部分提出了问题,我得到了一个非常快的答案: 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 之后,一切都像魅力一样。

于 2017-04-10T12:23:25.863 回答