I know this might get an answer here, however that goes more for lazy loading implementation itself.
So, this is a typical UI-Router
config block:
app.config(function($stateProvider, $urlRouterProvider, $injector) {
$stateProvider
.state('home', {
url: '/home',
templateUrl: 'view_home.html', // Actually SHOULD BE result of a XHR request ....
controller: 'HomeCtrl'
});
});
But what if I want to load such templateUrl
when it's requested ($stageChangeStart
) and it would be AJAX request based.
How should it be implemented? How are LARGE angular applications dealing with this?
We should (in this case) use
TemplateProvider
. Small cite from doc:Templates
And there is even more.
We can use cooperation with really powerful
$templateRequest
In this Q & A (Angular UI-Router dynamic routing based on slug from API Ajax Call. Load view based on slug) we can see so simple
templateProvider
defintionand the result is also chached...
There are some other links to similar Q & A, including working examples