Currently, I am using $http in a controller to retrieve data and display it to the user. However, once the data is fetched for the first time, I do not want to fetch it again when moving between different tabs or controllers. My expertise lies in web development and AngularJS, but I am struggling to prevent the repeated fetching of data. The code snippet below was my attempt at achieving this, but unfortunately, the data is still being fetched every time.
// Check if data has already been retrieved
if (angular.isDefined($scope.data)) {
console.log("Data already exists, no need to fetch again");
return;
} else {
console.log("Fetch data for the first time");
}
$http.post('/api/data'......