I'd like to get localized templates like:
'/templates/en/main/index'
'/templates/fr/main/index'
so each time I have a templateUrl, I wrap it in a function which relies on a global variable bearing the locale like so:
templateUrl: function(){ return localizePath('/templates/main/index'); }
// returns '/templates/locale/main/index' depending on he locale
I have to retrieve the locale through an ajax call so I obviously need to pause state activation. I tried the following but it doesnt stop the router to try to fetch the template:
var initialized = false;
$rootScope.$on('$stateChangeStart', function(event, toState, toParams) {
if (!initialized) {
event.preventDefault();
return sessionSvc.getLocale.then(function() {
initialized = true;
$state.go(toState, toParams);
});
}
});
Then the router tries to get the template at the following path: '/templates/undefined/main/index'
.
How could I make the ui-router wait before trying to fetch the template?