I have 3 controllers that do similar tasks:
- PastController queries an API for past system outages.
- CurrentController queries an API for current system outages
- FutureController queries an API for future system outages
They are each unique (despite their similar functions). However, they all begin by defining the same $scope
variables:
app.controller("PastController", function ($scope) {
$scope.Outages = "";
$scope.loading = 0;
$scope.nothing = 0;
$scope.error = 0;
//--- code continues ---//
});
app.controller("CurrentController", function ($scope) {
$scope.Outages = "";
$scope.loading = 0;
$scope.nothing = 0;
$scope.error = 0;
//--- code continues ---//
});
app.controller("FutureController", function ($scope) {
$scope.Outages = "";
$scope.loading = 0;
$scope.nothing = 0;
$scope.error = 0;
//--- code continues ---//
});
Can I use a service or factory to initialize those variables in one place rather than repeating the code?