简体   繁体   中英

Unknown provider error when deploying Rails/AngularJS app to Heroku

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:

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'];

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

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) {
  ...
}];

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

See mroe here

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

.controller method,

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM