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

前端 未结 3 746
别那么骄傲
别那么骄傲 2021-02-02 11:30

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

var MyController = function(renamed$scope, renamedGreeter) {
...
}
MyController.$inj         


        
相关标签:
3条回答
  • 2021-02-02 11:50

    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()
    ]
    
    0 讨论(0)
  • 2021-02-02 11:52

    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

    0 讨论(0)
  • 2021-02-02 12:05

    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}
          });
        }]);
    
    0 讨论(0)
提交回复
热议问题