Join the social network of Tech Nerds, increase skill rank, get work, manage projects...
 
  • Iterate json data in angularJS

    • 0
    • 1
    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 482
    Comment on it

    While working for an autocomplete funtionality in angularJS encountered a problem where instead of the JSON we need to iterate each element and have to make an Array of string.

    For iterating the JSON data(from server side), we used:

    $scope.complete = function(){
     
       WebService.getData($scope.search)
      .then(function(response){
    
       $scope.data = response.data.dataList;
       
                //we can use function(item) instead of function(item, index) if index number is not required
       angular.forEach($scope.data, function(item, index){
            $scope.values[index] = item.data1+","+item.data2;
          })
         
       $("#suggestion").autocomplete({ source: $scope.values });
       
      },function(error){
       console.log('error');
      });
      }

    Here scope.values is array of string, where we have put all the data.

 0 Comment(s)

Sign In
                           OR                           
                           OR                           
Register

Sign up using

                           OR                           
Forgot Password
Fill out the form below and instructions to reset your password will be emailed to you:
Reset Password
Fill out the form below and reset your password: