ocLazyLoad和Angular UI路由器

时间:2016-11-27 16:46:34

标签: angularjs angular-ui-router oclazyload

当我进入特定的嵌套状态时,我使用oclazyload动态加载Angular控制器。

那个嵌套状态:

.state('login.home', {
  url: "home",
  views: {
    "nav-right": {
      templateProvider: function($http, $stateParams) {
        return $http({
          method: 'GET',
          url: '/homeVnR'
        }).then(function successCallback(html) {
          return html.data;
        });
      }
    },
    "content@": {
      templateProvider: function($http, $stateParams) {
        return $http({
          method: 'GET',
          url: '/homeV'
        }).then(function successCallback(html) {
          return html.data;
        });
      },
      controller: "authhomeCtrl"
    }
  },
  resolve: {
    loadMyCtrl: ['$ocLazyLoad', function($ocLazyLoad) {
      // you can lazy load files for an existing module
      return $ocLazyLoad.load('authHome')
    }]
  }
  //all other states go below
})

您可以在content@视图中看到我的决心。

authHome的定义如下:

app.config(['$ocLazyLoadProvider', function($ocLazyLoadProvider) {
  $ocLazyLoadProvider.config({
      debug:  true,
      events: true,
      modules: [{
        name:"authHome",
        files: [
          "/homeC.js"
        ],
      }]
  });
}]);  

我在我的ajax请求中看到/homeC.js被点击并使用正确的Javascript获得200回。

看起来像这样:

app.controller('authhomeCtrl', ['$scope', '$http', '$timeout', '$interval', '$filter', '$uibModal', '$state', '$uibModalInstance', function($scope, $http, $timeout, $interval, $filter, $uibModal, $state, $uibModalInstance) {
scope.viewAttempt = function(){
alert("VIEW!");
}   
}]);

但是我收到了一个错误:

  

Argument' authhomeCtrl'不是一个功能...

如果lazyload成功加载它,为什么不定义?

我做错了什么?

0 个答案:

没有答案
相关问题