I have two pages where I have 1 common tab which contains some functionality. I have already code ready for that tab for 1 page and now I want to reuse all that code in my second page without duplicating the code.
For example, this is my code for page 1 of tab :
app.controller('myCtrl', ['$scope', '$window', 'myService', '$filter', function ($scope, $window, myService,$filter) {
$scope.myObj = [
{id:1,location : null},
{id:2,location : null}
]
//Lots of other variables here which are common and will be used in both the tabs and lots of methods which are also common
}]);
$scope.myObj is heavily used in all methods which will be common in both the tabs so I would like to have 1 common js file in which I will keep all this common variables and methods so that I don't have to copy-paste all these methods in both the controller of 2 pages to avoid code duplication.
I found 1 example like below but I am not getting how to share methods and complex variables like my $scope.myObj: