mefe
mefe

Reputation: 317

AngularJS + Rails: Unknown provider: e

After moving to production server using Rails 4 and AngularJS, I came across error: [$injector:modulerr] Failed to instantiate module EcoApp due to: Error: [$injector:unpr] Unknown provider: e. After reading other stackoverflow questions and angular docs, I suppose the error appears because of minification. Unfortunately, I don't know angular good enough and after several attempts to fix my code, I decided to search for help here.

My controller file (in CoffeeScript):

angular.module('EcoApp')
.controller 'MyTripsCtrl', ($scope, $http) ->

  $http.get('/mytrips.json').success((data, status, headers, config) ->

    $scope.mytrips = data

    return

  ).error (data, status, headers, config) ->

    # log error

    return

  return


.controller 'NavbarIsActive', ($scope, $location) ->

  $scope.isActive = (select_path) ->

    select_path == $location.path()



  return


.controller 'NavbarIsActive2', [

  '$scope'

  '$location'

  ($scope, $location) ->

    $scope.isActive = (select_path) ->

      select_path == $location.path()

    return
]

As you can see, I tried to fix controller NavbarIsActive, which in my opinion is cause of trouble, but with no results. Any help would be much appreciated!

Upvotes: 2

Views: 906

Answers (1)

deceze
deceze

Reputation: 522081

Yes, the problem is likely minification. If a minifier garbles your code into this:

.controller('Foobar', function (e) { .. })

then Angular doesn't have any information about what exactly it needs to inject. That's why the alternative injection syntax exists, which you need to use everywhere:

.controller 'Foobar', ['$scope', '$location', ($scope, $location) ->
    ..
]

You specify each dependency twice: once as a string, which will not get minified, and the second time as an arbitrary variable name in your actual function signature.

Upvotes: 3

Related Questions