I have a child state that fills up named views in the parent state (header, content). They both share the same data, however, and I don't want make a redundant second controller but seems like that's one of my only options. I could just use one view but it would then have too much markup which looks messy.
I read the docs here and the example they showed is for each view in the state to have it's own controller.
This is not ideal for my scenario. For example, ui-router says I have to do this:
.state('root.profile', {
url: '@:slug',
views: {
'header': {
templateUrl: 'app/profile/profile-header.html',
controller: 'ProfileHeaderController as profileHeader'
},
'content': {
templateUrl: 'app/profile/profile-body.html',
controller: 'ProfileBodyController as profileBody'
}
}
});
.. and I'd much rather do this:
.state('root.profile', {
url: '@:slug',
views: {
'header': {
templateUrl: 'app/profile/profile-header.html'
},
'content': {
templateUrl: 'app/profile/profile-body.html'
}
},
controller: 'ProfileController as profile'
});
The second option works better for me because as I said they share the same data and I would rather not reproduce a lot of the same logic twice, but unfortunately it doesn't work.
I am already using a service for the one controller. I wouldn't want to have to create another service just to store one set of values to use in both controllers cause that's still not really DRY.
Is there any work-around for something like this?