Reputation: 2653
I have one state in my ui-router config:
state("objects",
url: "/:type/"
)
And I need render different templates based on :type
params. For example, when user trying access /buy
, I need render template /views/objects/buy.html
, when /rent
— /views/objects/rent.html
.
What can help me?
Upvotes: 2
Views: 160
Reputation: 56
If I've understood you correctly. For example, if you have base url objects Your state will be:
.state('objects.rent') {
url: "/rent",
data: '{name: 'rent'},
views: {
// for one or multiple views
'rentView': {templateUrl: '/views/objects/rent.html'}
}
}
// If you need to get something or initialize:
$rootScope.$on('$stateChangeSuccess',
function(event, toState, toParams, fromState, fromParams){
if ($rootScope.$state.current.data !== undefined && $rootScope.$state.current.data.name !== undefined && $rootScope.$state.current.data.name === 'rent') {
// doSomething
}
});
Upvotes: 1