私は ui-router を使用しており、独自のコントローラーを持つコントローラーと子ビューを持つ親ビューを使用している構成があります。子ビューの 1 つに移動するたびに、親コントローラーが再度インスタンス化されるため、サーバーに対して不要な要求が実行されます。子の状態間を移動し、親コントローラーによって解決された変数を再利用できるようにしたいと考えています。
親コントローラーが毎回インスタンス化されないようにするにはどうすればよいですか?
これは私のルーティング設定です:
$stateProvider
.state('researchLayoutEditor', {
url: '/research/:researchId/layoutEditor/:orderInGroup',
controller: 'layoutEditorController',
controllerAs: 'layoutEditorCtrl',
templateUrl: 'app/researchManagement/researchLayoutEditor/layoutEditor.html',
redirectTo: 'researchLayoutEditor.slide',
params: {
group: 'A',
orderInGroup: '0'
},
resolve: {
researchLayout: function (researchesService, $stateParams) {
return researchesService.getResearchLayout($stateParams.researchId, false);
},
research: function (researchesService, $stateParams) {
return researchesService.getResearch($stateParams.researchId);
}
}
}).state('researchLayoutEditor.slide', {
url: '/textual',
templateUrl: 'app/researchManagement/researchLayoutEditor/textSlide.html',
controller: 'textSlideController',
controllerAs: 'txtSlide'
}).state('researchLayoutEditor.movie', {
url: '/video',
templateUrl: 'app/researchManagement/researchLayoutEditor/movieSlide.html',
controller: 'movieSlideController',
controllerAs: 'movieSlide',
resolve: {
movieCategories: function (utilsService) {
return utilsService.getVideoCategories();
}
}
}).state('researchLayoutEditor.memory', {
url: '/memory',
templateUrl: 'app/researchManagement/researchLayoutEditor/memorySlide.html',
controller: 'memorySlideController',
controllerAs: 'memorySlide'
}).state('researchLayoutEditor.question', {
url: '/question',
templateUrl: 'app/researchManagement/researchLayoutEditor/questionSlide.html',
controller: 'questionSlideController',
controllerAs: 'questionSlide'
});
これが HTML です。
<div id="mainContent">
<!-- our nested state views will be injected here -->
<div ui-view class="inner-content"></div>
</div>