This might be a common problem that a angularjs dev will encounter, and I don't know if this was already been answered in the past, a brief searching doesn't give me results.
Okay, I have 2 related routes, likes so:
$stateProvider
.state('user', {
abstract: true,
templateUrl: 'views/sometemplate.html',
controller: 'UserCtrl'
})
.state('user.collection', {
url: '/user',
resolve: {
users: function(User) {
return User.query()
}
},
})
.state('user.detail', {
url: '/user/:id',
resolve: {
user: function($stateParams, User) {
return User.get({id: $stateParams.id})
}
},
});
The problem with this is that if I access the route /user
, the controller requires two 2 provider, users and user.
.controller('UserCtrl', function ($scope, user, users) {
$scope.user = user;
$scope.users = users;
})
Do you recommend having 2 separate controllers for this, if yes, how do you usually name your controllers, but I don't think its nice to have 2 different controllers, since it is not totally different, same domain still.