23

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'];
John
  • 6,404
  • 14
  • 54
  • 106

3 Answers3

26

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) {
  ...
}];
John
  • 6,404
  • 14
  • 54
  • 106
5

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

See mroe here

Renan Tomal Fernandes
  • 10,978
  • 4
  • 48
  • 31
5

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

taro
  • 699
  • 1
  • 9
  • 20