I will recommend you using Memoization pattern along with service and reuse the service in the controller
Pls check the below sample code
var app = angular.module('plunker', []);
app.service('cache', function ($http,$q) {
var mycache={};
return {
getdata: function (key) {
var deferred = $q.defer();
if (mycache[key]) {
deferred.resolve(mycache[key]);
}
else {
$http.get('TextFile.txt').then(function (data) {
mycache[key] = data.data;
deferred.resolve(mycache[key]);
});
}
return deferred.promise;
}
}
});
app.controller('test', function ($scope, cache) {
cache.getdata('cache').then(function (data) {
$scope.data = data;
});
});
app.controller('test1', function ($scope, cache) {
//since data is already cached now it will server the cached data
cache.getdata('cache').then(function (data) {
$scope.data = data;
});
});