问题
I am getting files from directory('app/jsonfiles') in node.js, and I am not sure how can I send this list of files to my front-end as options in select list to write one common get request for getting the data of selected file.
partial Plnkr. Please let me know that how can I get my list of files in my angular from my server.js to display in my dropdown and Thanks in advance for help !
回答1:
Inject Main service into MainCtrl and call the service.
var app = angular.module('plunker', [MainService]);
app.controller('MainCtrl', function($scope,$http, $timeout, Main) {
$scope.JSONFiles = [];
Main.get().success(function(data){
data.forEach(function(obj){
$scope.JSONFiles.push(obj);
})
});
$scope.selectedjson ="";
$scope.textAreaData = "";
$scope.optionChanged = function(){
$scope.textAreaData = $scope.selectedjson;
}
});
来源:https://stackoverflow.com/questions/39849899/how-to-send-list-of-files-to-angularjs-options-from-node-js