John
John

Reputation: 6622

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

Upvotes: 23

Views: 6218

Answers (3)

taro
taro

Reputation: 719

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

Upvotes: 5

John
John

Reputation: 6622

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

Upvotes: 26

Renan Tomal Fernandes
Renan Tomal Fernandes

Reputation: 10978

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

See mroe here

Upvotes: 5

Related Questions