Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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'];
like image 673
John Avatar asked Nov 28 '12 15:11

John


3 Answers

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) {
  ...
}];
like image 99
John Avatar answered Oct 22 '22 17:10

John


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

See mroe here

like image 26
Renan Tomal Fernandes Avatar answered Oct 22 '22 15:10

Renan Tomal Fernandes


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

like image 5
taro Avatar answered Oct 22 '22 16:10

taro