angular.js - ocLazyLoad配合ui-router延迟加载controller,controller提示 not a
本文介绍了angular.js - ocLazyLoad配合ui-router延迟加载controller,controller提示 not a的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
问 题
问题如题。延迟加载进controller文件后,controller提示不存在。
贴代码:
state:
//state
$stateProvider.state('user.performance', {
url: '/performances',
views: {
'': {
controller: 'PerformanceCtrl',
templateUrl: 'tpl/user/performance'
}
},
resolve:{
loadPerformanceCtrl: ["$ocLazyLoad", function ($ocLazyLoad) {
return $ocLazyLoad.load('/app/performance/performance.js');//js文件有成功加载进来
}]
}
})
performance.js
;(function () {
'use strict';
myApp.controller('PerformanceCtrl', [
'$scope',
'PerformanceService',
function ($scope, PerformanceService) {
console.log('PerformanceCtrl');
//...
])
})();
// myApp 在此前加载的js中已经定义过。var myApp = angular.module('zwb', []);
报错: Argument 'PerformanceCtrl' is not a
解决方案
我捣鼓了下,发现:
当我创建一个新的module时,
$ocLazyLoad.load()
加载进来的component registered成功,如下
angular.module('testtest', []).controller('PerformanceCtrl', [
//...
])
由上边,我想到angular的另一个点,当module不带参时是getter,所以尝试如下:
angular.module('order').controller('PerformanceCtrl', [
//...
])
ocLazyLoad debug 提示ocLazyLoad.moduleReloaded order
,这样perfomance下的component被load进来,register也成功。
纠结了蛮久,对angular的理解以及引入组件的熟悉度还很不够。感谢 G_Koala_C 的回答,thank you~
这篇关于angular.js - ocLazyLoad配合ui-router延迟加载controller,controller提示 not a的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文