admin管理员组

文章数量:1417653

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.

本文标签: javascriptAngularJS uirouterresolve http dependency is lost upon minifyStack Overflow