2

I ve been trying to populate a searchable drop down list using json data with angularjs , i ve pushed the json data in the server and i ve been able to receive the response from the server if i use the get method.I dont know exactly how to query the json data and populate them in the search bar. I ve attached the controller script and the html

var app=angular.module('myapp',[]);
app.controller('myctrl',function($scope,$http){
    $http({
        method:"GET",
        url:"http://localhost:5050/codes?val="}).then(function mySuccess(response){
        $scope.msg=response.data;
    },function myError(response){
        $scope.msg=response.statusText;
    });
});
<!DOCTYPE html>

signals

<body>
    <div ng-app="myapp" ng-controller="myctrl" >
        <select ng-model="search">
            <option ng-repeat="names in msg " value="{{names.value}}"></option>
            </select>
    </div>
</body>

This is the sample json data that i am feeding to the page from the local host i have to populate the search bar with the "value" part of the json data.

{"codes":
   [{"code": "NSE/AHLWEST", "value": "Asian Hotels (West) Limited"}, 
   {"code": "NSE/JINDALSWHL", "value": "Jindal South West Holding Limited"}, 
   {"code": "NSE/WIPL", "value": "The Western India Plywoods Limited"}, 
   {"code": "NSE/WSTCSTPAPR", "value": "West Coast Paper Mills Limited"}]
 }
1
  • You are receiving JSON as an objects so better use msg.codes in your ng-repeat tag Commented Dec 15, 2017 at 8:29

2 Answers 2

2

Need to access the codes property. And also it is better to use ng-options rather than ng-repeat in this scenario

<select ng-model="search" ng-options="names.value as names.code for names in msg.codes"> 
</select>
Sign up to request clarification or add additional context in comments.

2 Comments

Than you so much
@SathishSridhar No problem :)
1

You need to access codes

<option ng-repeat="names in msg.codes " value="{{names.value}}"></option>

2 Comments

Than you so much :)
The above code worked better , i thought i could have multiple answers.Thanks once again :)

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.