问题如题。延迟加载进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
I fiddled with it and found:
When I create a new module,
$ocLazyLoad.load()
The loaded component is registered successfully, as shown belowFrom the above, I thought of another point in angular. When the module takes no parameters, it is a getter, so try the following:
ocLazyLoad debug prompt
ocLazyLoad.moduleReloaded order
, in this way, the component under performance is loaded and the register is successful.I have been struggling for a long time, and my understanding of angular and the familiarity with introducing components are still not enough. Thanks for G_Koala_C’s answer, thank you~
The resolve of routing usually preloads the data used by the current state, and then loads the page after the data is loaded. In your situation, there is no need for lazy loading. Isn't it completely superfluous? I don’t know where your error lies. There are probably two types:
1. Remove lazy loading, which is of no use.
2. Change the controller in views to loadPerformanceCtrl, and resolve has been renamed directly. Not sure if it works.