Apologies if this question seems trivial, but I am just getting started with angularJS.
I have created two controllers: seekerController
and wizardController
...
Within the wizardController
, there is a Scope object called chat
, which is being manipulated by several functions.
Now, as I switch back to the seekerController
, I realize that I need to replicate the same chat
Scope object and its associated functions from the wizardController
.
One way to do this would be to simply copy all the code into the other controller, but that would lead to duplication across my project...
So, I'm seeking a solution where I can centralize this logic in one place yet still access the chat
Scope object and functions from both controllers seamlessly.
Update - Code Samples:
//seekerController
angular.module('cg.seeker', [])
.controller('SeekerController', ['$scope', 'seekerService', 'timeService', 'chatService', '$stateParams', 'toastr',
function ($scope, seekerService, timeService, chatService, $stateParams, toastr) {
...
// CHAT FUNCTIONALITY
$scope.chat = { close: true };
chatService.unreadCount(function(count){
$scope.chat.unreadCount = count;
$scope.$apply();
});
// Rest of the functions for manipulating chat object...
...
I've replicated the above code in another controller WizardController
, verbatim without modifications... and even a third controller also has some of these functionalities, though not all.