I think you misunderstood the responsibility of controllers in angular.
How to use controllers from angular docs:
Use controllers to:
Do not use controllers to:
- Manipulate DOM — Controllers should contain only business logic.
- Putting any presentation logic into Controllers significantly affects
its testability.
- Angular has databinding for most cases and directives
to encapsulate manual DOM manipulation.
- Format input — Use angular
form controls instead.
- Filter output — Use angular filters instead.
- Share code or state across controllers — Use angular services instead.
- Manage the life-cycle of other components (for example, to create
service instances).
So if you want to create some block of reusable code, you just need to create an angular service, which will include function with needed logic. Then you can inject it to both controllers and they will have necessary functionality.
Example:
app.controller('LoginController', function ($scope, $cookieStore, helperService) {
$cookieStore.put('email', 'test@gmail.com');
$scope.wecomeMessage = helperService.getMessage();
});
// Home controller
app.controller('HomeController', function ($scope, $cookieStore, $location, helperService) {
$scope.wecomeMessage = helperService.getMessage();
});
app.service('helperService', function ($cookieStore) {
this.getMessage = function () {
return $cookieStore.get('email') != null ? $cookieStore.get('email') : "";
};
});