ocLazyLoad and Angular UI Router

核能气质少年 提交于 2019-12-13 07:39:10

问题


I'm using oclazyload to load an Angular controller dynamically, when I enter a specific nested state.

That nested state:

.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
})

You can see it in my resolve in the content@ view.

authHome is defined like so:

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

I see in my ajax requests that /homeC.js is hit and gets a 200 back with the proper Javascript.

It looks like this:

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

But I get an error:

Argument 'authhomeCtrl' is not a function...

Why is it undefined if the lazyload successfully loaded it?

What am I doing wrong?

来源:https://stackoverflow.com/questions/40831327/oclazyload-and-angular-ui-router

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