I operate a factory where I utilize a function called getExpenseList that performs an ajax call to fetch data from the expense table.
Currently, I have two routes set up - one for listing expenses and another for adding new expenses. However, whenever I navigate back to the listing page after a route change, the ajax call is triggered again. What I would like to achieve is to store the expense object during the initial ajax call and reference the same object until manual browser refresh occurs.
If you can provide assistance in achieving this goal, here is the factory code snippet below. My preference would be to use this.expenses if the data is already present.
admin.factory('expenseFact', ['$http', function($http) {
var expense = {};
this.expenses = "";
expense.getExpenseList = function() {
this.expenses = $http({
headers: {
'Content-Type': 'application/x-www-form-urlencoded'
},
method: "GET",
url: base_url + "rest/expenses"
});
return this.expenses;
};
return expense;
}]);
Additionally, here is my controller code for reference:
admin.controller('expenseLandCtrl', function ($scope,$rootScope,expenseFact) {
$scope.pageTitle = $rootScope.pageTitle;
expenseFact.getExpenseList().then(function (data) {
$scope.expenses = data.data;
});
});
admin.controller('expenseAddCtrl', function ($scope,$rootScope,expenseFact) {
$scope.pageTitle = $rootScope.pageTitle;
});