Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Rails 3 + angularjs + minification does not work in production: Unknown provider: eProvider

Tags:

I've followed all the instructions I can find for fixing minification, e.g.

var MyController = function(renamed$scope, renamedGreeter) { ... } MyController.$inject = ['$scope', 'greeter']; 

and

someModule.factory('greeter', ['$window', function(renamed$window) { ...; }]); 

yet angular refuses to work still. It always throws the error "Unknown provider: eProvider"

Here are my two attempts to get it working... can anyone help?

https://github.com/jemminger/angular-test1

https://github.com/jemminger/angular-test2

They've already had the assets precompiled and development mode is configured to work as production, so you should just be able to "rails s" to see it (not) work.

like image 837
jemminger Avatar asked Nov 19 '12 17:11

jemminger


2 Answers

Found it! They never said to apply the injection fixes to services too... The solution is to change this:

angular.module('itemServices', ['ngResource']).     factory('Item', function($resource){       return $resource('items/:item_id.json', {}, {         query: {method:'GET', params:{ item_id: 'all' }, isArray:true}       });     }); 

to this:

angular.module('itemServices', ['ngResource']).     factory('Item', ['$resource', function($resource){       return $resource('items/:item_id.json', {}, {         query: {method:'GET', params:{ item_id: 'all' }, isArray:true}       });     }]); 
like image 97
jemminger Avatar answered Oct 07 '22 17:10

jemminger


Remember, to also use DI on controllers within directives. Took me hours... CS example:

wrong:

controller: ($scope) ->   $scope.closeModal = ->     ModalService.close() 

right:

controller: ["$scope"   ($scope) ->     $scope.closeModal = ->       ModalService.close() ] 
like image 42
cache.zero Avatar answered Oct 07 '22 17:10

cache.zero