将Rails / AngularJS应用程序部署到Heroku时出现未知的提供程序错误

时间:2023-01-21 00:16:25

I have a Rails/AngularJS app which works fine in local development environment. However, when I deploy this app to Heroku the AngularJS doesn't work an returns this error:

我有一个Rails / AngularJS应用程序,可以在本地开发环境中正常工作。但是,当我将此应用程序部署到Heroku时,AngularJS无效,则返回此错误:

Unknown provider: eProvider <- e

I did a bit of research and it seems it has something to do with the precompiling and minification of the assets, but I don't know what to do to solve this. Any ideas? Thanks!

我做了一些研究,似乎它与资产的预编译和缩小有关,但我不知道如何解决这个问题。有任何想法吗?谢谢!

This is how the controller looks:

这是控制器的外观:

function RemindersCtrl($scope, $http) {
  $http.get('/reminders.json').success(function(data) {
    $scope.reminders = data;
    console.log(data);
  });
}

And this is the code in the view:

这是视图中的代码:

    %section.reminders
      %div{"ng-controller" => "RemindersCtrl"}
        %ul
          %li{"ng-repeat" => "reminder in reminders"}
            .title {{reminder.title}}

Update: I changed the controller to this, but with the same result:

更新:我将控制器更改为此,但结果相同:

var RemindersCtrl = function($scope, $http) {
  $http.get('/reminders.json').success(function(data) {
    $scope.reminders = data;
    console.log(data);
  });
}
RemindersCtrl.$inject = ['$scope','$http'];

3 个解决方案

#1


27  

According to AngularJS tutorial (http://docs.angularjs.org/tutorial/step_05) you can either add this to the controller to prevent minification problems:

根据AngularJS教程(http://docs.angularjs.org/tutorial/step_05),您可以将其添加到控制器以防止缩小问题:

function RemindersCtrl($scope, $http) {
  ...
}
RemindersCtrl.$inject = ['$scope', '$http'];

or instead of defining a function like this:

或者不是像这样定义一个函数:

function RemindersCtrl($scope, $http) {
  ...
}

it should be done like this:

它应该这样做:

var RemindersCtrl = ['$scope', '$http', function($scope, $http) {
  ...
}];

#2


5  

You are probably defining your controller as FooController = function($http) {}, you should define as FooController = ["$http", function($http){}]

您可能将控制器定义为FooController = function($ http){},您应该定义为FooController = [“$ http”,函数($ http){}]

See mroe here

看到这里的mroe

#3


5  

Angular team (and also generally speaking) recommends that we do not pollute the global scope.

Angular团队(一般而言)建议我们不要污染全球范围。

.controller method,

.controller方法,

var myApp = angular.module('myApp',[]);

myApp.controller('GreetingCtrl', ['$scope', function($scope) {
  $scope.greeting = 'Hola!';
}]);

worked fine for me. This is documented on Angular Understanding Controllers documentation

对我来说很好。这在Angular Understanding Controllers文档中有记录

#1


27  

According to AngularJS tutorial (http://docs.angularjs.org/tutorial/step_05) you can either add this to the controller to prevent minification problems:

根据AngularJS教程(http://docs.angularjs.org/tutorial/step_05),您可以将其添加到控制器以防止缩小问题:

function RemindersCtrl($scope, $http) {
  ...
}
RemindersCtrl.$inject = ['$scope', '$http'];

or instead of defining a function like this:

或者不是像这样定义一个函数:

function RemindersCtrl($scope, $http) {
  ...
}

it should be done like this:

它应该这样做:

var RemindersCtrl = ['$scope', '$http', function($scope, $http) {
  ...
}];

#2


5  

You are probably defining your controller as FooController = function($http) {}, you should define as FooController = ["$http", function($http){}]

您可能将控制器定义为FooController = function($ http){},您应该定义为FooController = [“$ http”,函数($ http){}]

See mroe here

看到这里的mroe

#3


5  

Angular team (and also generally speaking) recommends that we do not pollute the global scope.

Angular团队(一般而言)建议我们不要污染全球范围。

.controller method,

.controller方法,

var myApp = angular.module('myApp',[]);

myApp.controller('GreetingCtrl', ['$scope', function($scope) {
  $scope.greeting = 'Hola!';
}]);

worked fine for me. This is documented on Angular Understanding Controllers documentation

对我来说很好。这在Angular Understanding Controllers文档中有记录