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

旧城冷巷雨未停 提交于 2019-12-03 06:53:38

问题


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.


回答1:


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



回答2:


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()
]



回答3:


Make sure to apply the DI pattern to ALL function definitions that require injection within your module. It can be easy to miss one. If you're using a routeProvider, factory, services, etc., they all need to have the DI pattern applied. I ended up deploying multiple times before I caught them all :P



来源:https://stackoverflow.com/questions/13459452/rails-3-angularjs-minification-does-not-work-in-production-unknown-provider

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!