Currently, I am utilizing Angular's new router components alongside JavaScript. Within my codebase, there are multiple controllers similar to the example below.
My goal is to implement a single function to all controllers so that I do not have to repeat it in each one individually.
function HomeController(authService, factoryClient) {
console.log('this is home controller');
this = doCommonController.bind(this); // encountering an error here
// The 'this' object should comprise currentUser, authService, logout, and testVar properties
console.log(this);
}
The function in question is:
var doCommonController = function (authService, currentUser) {
this.testVar = 'value';
this.authService = authService;
this.currentUser = currentUser;
this.logout = this.authService.logout;
}
Additionally, how can I transmit the authService and factoryClient from the controller to be accessible within doCommonController?