0

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 !

2
  • Currently, are you able to get data from backend? Commented Oct 4, 2016 at 10:36
  • @Ravi Teja, yes, I am getting those filenames and it's data on my console(you can check in server.js as I mentioned): console.log(filename); and console.log(data[filename]); Commented Oct 4, 2016 at 10:38

1 Answer 1

0

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;
    }

    });
Sign up to request clarification or add additional context in comments.

4 Comments

it's saying that Unexpected token {(at Main.get().success(data){ ) and hence MainCtrl is not a function, got undefined error is coming.
Main.get().success(function(data){ data.forEach(function(obj){ $scope.JSONFiles.push(obj); }) }); //}); $scope.selectedjson =""; $scope.textAreaData = ""; $scope.optionChanged = function(){ $scope.textAreaData = $scope.selectedjson; } Giving data.forEach is not a function (and one more: } is added extra in the above script, and I removed extra }, checked, getting data.forEach is not a function error. please find)
yes, I have tried the above, I am getting: TypeError: data.forEach is not a function error.
Can try to put a debugger point at data.forEach and see whether data is populated.. with data from backend?

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.