我正在尝试读取服务器上的文件列表。HTTP GET 方法服务返回文件列表,但控制器中的范围变量未使用返回值进行更新。你能帮我找出问题所在吗?
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>