Reputation: 65
I am working on a Front-end web application on Angular JS and using UI-router for routing.
Now i have a child state that is same across multiple states.
$stateProvider.state('app.user1.viewProfile1', {
url: '/:profileURL',
views: {
'[email protected]': {
component: 'profile'
}
}
});
$stateProvider.state('app.user2.viewProfile1', {
url: '/:profileURL',
views: {
'[email protected]': {
component: 'profile'
}
}
});
$stateProvider.state('app.user3.viewProfile1', {
url: '/:profileURL',
views: {
'[email protected]': {
component: 'profile'
}
}
});
Is there a way to not replicate the viewProfile child and subsequent state definition, any way to append same child to multiple parents?
Upvotes: 1
Views: 569
Reputation: 93
You can drop states in a loop and & iterate over the states like -
angular.forEach(["parent.state1","parent.state2","parent.state3"], function(parent) {
$stateProvider.state(parent+".childState", {
url: '/child',
...
});
});
Upvotes: 2