Hi ,
i have the following code :
.state(‘service_tab.home’, {
url: ‘/home’,
views: {
‘service_home-tab’: {
//templateUrl: ‘templates/staff/service_home.html’,
templateUrl: function() {
if (false) {
return “templates/staff/service_home.html”;
}
else {
return “templates/student/service_home.html”;
}
},
controller: ‘service_HomeTabCtrl’
}
} ,
data: {
authorizedRoles: [USER_ROLES.staff ]
}
})
the above code only works if the condition is True ,
i need to dynamically redirect the user based on the USER_ROLES
thank you
the first answer seems promising.
Check templateProvider
Thankx for the quick replay , but what i need exactly is getting authorizedRoles value daynamically from e.g. localstorage …etc
data: {
authorizedRoles: [USER_ROLES.staff ]
}
sorry , i got it , using templateprovider
.state('service_tab.home', {url: '/home',
views: {
'service_home-tab': {
controller: 'service_HomeTabCtrl',
templateProvider: ['localStorageService','$stateParams','$templateFactory' ,function(localStorageService,$stateParams,$templateFactory){
var authData = localStorageService.get('authorizationData');
if (authData) {
if (authData.role == 'staff'){
return $templateFactory.fromUrl('templates/staff/service_home.html',$stateParams);
}else{
return $templateFactory.fromUrl('templates/student/service_home.html',$stateParams);
}
}
}]
}
}
})