I have a controller as HomeController in my home.html page and I want to call the same controller and its contents in my about.html page. The below code is for Home page which will show the First name and Last name of the user and I want to call the same functionality like call the first name and last name in the about us page. How to do that? As of now I have just copied the whole and pasted in the about controller just changing the controller name from HomeController to AboutController.
(function () { 'use strict';
angular
.module('app')
.controller('HomeController', HomeController);
HomeController.$inject = ['UserService', '$rootScope','$scope', '$http'];
function HomeController(UserService, $rootScope,$scope, $http) {
var vm = this;
vm.user = null;
vm.allUsers = [];
vm.deleteUser = deleteUser;
initController();
function initController() {
loadCurrentUser();
loadAllUsers();
}
function loadCurrentUser() {
UserService.GetByUsername($rootScope.globals.currentUser.username)
.then(function (user) {
vm.user = user;
});
}
function loadAllUsers() {
UserService.GetAll()
.then(function (users) {
vm.allUsers = users;
});
}
function deleteUser(id) {
UserService.Delete(id)
.then(function () {
loadAllUsers();
});
}
$http.get('webservice').
then(function(response) {
$scope.user_message = response.data.data;
});
}
})();