난과 같이 컨트롤러를로드 할 AngularJS와 :레지스터 lazyloaded 컨트롤러는
.state({
name: 'app.search',
url: 'search?q&opts',
templateUrl: '/templates/search.html',
controller: 'SearchCtrl',
resolve: {
deps: function($util){
return $util.load(['/ctrl/SearchCtrl.js']);
}
}
})
컨트롤러의 부하를하지만 난 컨트롤러가 등록되지 않았 음을 믿고 저를 선도, 다음과 같은 오류가 발생합니다 :
Argument 'SearchCtrl' is not aNaNunction, got undefined
내 질문은, 어떻게 내가 컨트롤러를 등록 할 때 지연된로드 된 같이 표시됩니다.
컨트롤러는 다음과 같이 정의된다
app.module('app').controller('SearchCtrl',function(){
});
등록 할 내가 컨트롤러를 강제로 할 수있는 일이 있나요?
수정 앱이 이미 구성되어 있으며 모든 것이 작동합니다. 이 질문은 LAZYLOADING에만 적용됩니다.
문제는 정확히 정의 된 바와 같이 부트 스트랩 프로세스가 이미 실행 되었기 때문에 컨트롤러가 등록되지 않았습니다. lazyloaded 때 컨트롤러를 등록 할 수있는 몇 가지 방법을 찾고 있어요. 나는 사용자 정의 기능을 angular.module()
를 재정 의하여 그것을 자신을 해결할 수 있었다
load: function(){
if(arguments.length > 1){
var items = arguments;
}else{
var items = arguments[0];
}
var _self = this;
return $q(function(resolve,reject){
if(items.length == 0){
return resolve();
}
_self.async(items, function(item,next){
if(item.indexOf('.js') != -1){
_self.loadOne('script',item,next,function(err){
next(err);
});
}
else if(item.indexOf('.css') != -1){
_self.loadOne('link',item,next);
}else{
next();
}
},function(errors,results){
$timeout(function() {
$rootScope.$apply();// @Claies suggestion
if(errors){
reject(errors);
}else{
resolve();
}
});
});
});
},
별도로 선언 된 모듈이 있습니까? – Sajeetharan
앱 모듈? 당연하지. 이 앱은 이미 제작되었지만 모든 코드는 하나의 파일에 있습니다. 나는 모든 코드를 별도의 파일로 분할하려고 시도하고있다. – r3wt
로더가 컨트롤러 파일을로드하고 실행하지만 * resolve *가 반환되기 전에 * $ rootScope. $ apply()'*를 사용해야한다. oc-lazyLoad와 같이이 태스크를 위해 설계된 모듈을 사용할 수도 있습니다. https://oclazyload.readme.io/docs/with-your-router – Claies