I'm defining a page title in my state object as advised here.
$stateProvider
.state('project', {
url: '/projects/:origin/:owner/:name',
template: '<project></project>',
data : { pageTitle: 'Project page title'},
});
so i can access it this way later on:
$state.current.data.pageTitle
Now ... What i'd like to do is that instead of having a fixed value as pageTitle i'd like to access one the stateParams.
BEWARE, below exemple is not working, this is the way i'd like it to work.
$stateProvider
.state('project', {
url: '/projects/:origin/:owner/:name',
template: '<project></project>',
data : { pageTitle: $stateParams.name},
});
I could also use the attribute resolve :
resolve: { title: 'Project page title' },
For stateParams value i could do that:
resolve:{
pageTitle: ['$stateParams', function($stateParams){
return $stateParams.name;
}]
}
But then console.log($state.current.resolve.pageTitle); in my controller will return the entire function and not the result.
What would be the proper way to do that?
UPDATE :
The thing which i didn't mention is that i use angularJs with ES6 and i use a modular architecture. Therefore each component has its own scope.
You can check my previous post to have a better idea about the modular architecture i'm using.
I'm building a breadcrumb grabbing the parent states (using the defined pageTitle). Therefore defining the page title name in each module would be perfect.
So i can decide if the page title would be a fixed value "My page title" or a stateParams value.
Maybe this is totally wrong and this should not be done that way. Let me know if it is the case.