Reputation: 43491
I'm using the $routeProvider
and I want the route to load a different view depending on what is passed:
when('/tx/:txid', {
templateUrl: '/views/tx/view.html'
}).
If txid
matches a certain pattern, it should load one view. If it matches a different pattern, it should load a different view. Is this possible?
Upvotes: 0
Views: 283
Reputation: 1714
Have a look at dynamic templates.
when('/tx/:txid',
{
controller:ctrl,
templateUrl: function(params){
// your logic here...
return '/tx/diferentview/' + params.txid;
}
}
This should do the trick.
Upvotes: 1
Reputation: 193261
You can use function for dynamic views:
.when('/tx/:txid', {
templateUrl: function(routeParams) {
// return necessary view based on route params
return '/views/tx/view.html';
}
})
From documentation:
If templateUrl is a function, it will be called with the following parameters: {Array.} - route parameters extracted from the current $location.path() by applying the current route
Upvotes: 1