javascript - AngularJS UI-Router, resolve $http dependency is lost upon minify - Stack Overflow

I'm trying to resolve some data before the controller get's loaded. Works as expected on deve

I'm trying to resolve some data before the controller get's loaded. Works as expected on development code, but when I minify it, my $http get's replaced by e or whatever variable is available.

I can't inject $http in the angular.module("app", []).config. So I have no idea how to solve this problem.

angular.module("app", [
  "app.controllers"
  "app.directives"
  "app.filters"
  "app.services"
]).config ($stateProvider, $urlRouterProvider) ->

  $stateProvider.state("tab",
    url: "/tab"
    abstract: true
    templateUrl: "tpls/tabs.html"
  )

  .state("tab.programs",
    url: "/programs"
    abstract: true
    resolve:
      events: ($http) -> # $http get's replaced upon minification..
        $http.get('my.example.site/events.json')
          .then((data) ->
            data.data
          )

I'm trying to resolve some data before the controller get's loaded. Works as expected on development code, but when I minify it, my $http get's replaced by e or whatever variable is available.

I can't inject $http in the angular.module("app", []).config. So I have no idea how to solve this problem.

angular.module("app", [
  "app.controllers"
  "app.directives"
  "app.filters"
  "app.services"
]).config ($stateProvider, $urlRouterProvider) ->

  $stateProvider.state("tab",
    url: "/tab"
    abstract: true
    templateUrl: "tpls/tabs.html"
  )

  .state("tab.programs",
    url: "/programs"
    abstract: true
    resolve:
      events: ($http) -> # $http get's replaced upon minification..
        $http.get('my.example.site/events.json')
          .then((data) ->
            data.data
          )
Share Improve this question asked Apr 3, 2014 at 10:04 Martin BroderMartin Broder 3351 gold badge7 silver badges21 bronze badges
Add a ment  | 

2 Answers 2

Reset to default 5

Ok I've figured it out.

I have to inject it on the function itself. Like this:

  .state("tab.programs",
    url: "/programs"
    abstract: true
    resolve:
      events: ['$http', ($http) -> # $http now is injected
        $http.get('my.example.site/events.json')
          .then((data) ->
            data.data
          )
        ]

Coffeescript makes my brain hurt, but in Javascript you'd do

config(['$stateProvider', function($stateProvider) {

   ...

}]);

That is, an array containing your all dependencies as strings (in order) and then the function to run.

The minimizer won't mess with the strings, and Angular's DI framework understands that syntax.

发布者:admin,转转请注明出处:http://www.yc00.com/questions/1745279431a4620207.html

相关推荐

发表回复

评论列表(0条)

  • 暂无评论

联系我们

400-800-8888

在线咨询: QQ交谈

邮件:admin@example.com

工作时间:周一至周五,9:30-18:30,节假日休息

关注微信