I'm trying to read list of files on a on a server. The HTTP GET method service returns the list of files, but scope variable in controller is not getting updated with the return value. Can you please help me find what is going wrong ?
app.controller('RdaController', ['$scope', ', 'RdaService', function($scope, RdaService) {
$scope.listOfFilesOnCTP = "";
$scope.GetListOfFilesonCTP = function(path){
$scope.$apply(function(){
$scope.listOfFilesOnCTP = RdaService.getListOfFilesonCTP(encodeURIComponent(path));
});
//path = path.replace(/\//g, '_');
console.log($scope.listOfFilesOnCTP); //--> This scope variable does not get updated.
return $scope.listOfFilesOnCTP;
}
}]);
app.service('RdaService', ['$http', function($http) {
this.getListOfFilesonCTP = function(path){
return $http ({
method: "GET",
url: "../api/CTP/getFilesonCTP/"+ path,
headers: { 'Content-Type': 'application/json' }
}).success(function(data){
return data; //---> contains the expected value
}).error(function(data){
return data;
});
};
}]);
<div class="col-md-3" id="CTP Jobs">
<h3>JOBS</h3>
<table class="table table-striped"
ng-init="GetListOfFilesonCTP('/home/topas/rda_app/JOBS')"
ng-model="listOfFilesOnCTP"> <!-- This variable is not updated-->
<div ng-repeat="file in listOfFilesOnCTP">
<span><tr>{{file}}
</tr></span>
</div>
</table>
</div>