Take the 2-minute tour ×
Stack Overflow is a question and answer site for professional and enthusiast programmers. It's 100% free, no registration required.

I make a auto complete .First I download my data from server and then write anything on text field it filter with my stationCode.I have two thing in my json array stationCode and stationName array .Now I need to set the selected station code on input text field .Can you please tell me what is better way to set the value of station code on input text field whenever user select any row of autosuggest.

here is my code.

<!DOCTYPE html>
<html>
<head>
    <link rel="stylesheet" href="css/foundation.css" />




</head>
<body ng-app="myapp">
    <div ng-controller="cnt">
        <input type="text" ng-model="searchText.stationCode">
        <table ng-show="searchText.stationCode && searchText.stationCode.length != 0">

            <tr id="$index"ng-repeat= "a in d.data | filter:searchText" ng-click="getselectedRow(searchText)">
                   <td> {{a.stationCode}} </td>
                <td> {{a.stationName}} </td>


            </tr>
        </table>

    </div>
</body>
<script src="js/angular.js" type="text/javascript"></script>
<script src="js/app.js" type="text/javascript"></script>
</html>



function cnt($scope,$http){
    $http.get("http://184.106.159.143:8180/FGRailApps/jservices/rest/stationList")
        .success(function (data) {
           //alert(data);
            $scope.d=data;
        }).error(function(data){
                              alert("error")
        });

    $scope.getselectedRow=function(obj){
        alert(obj.stationCode)
    }


}

fiddle http://jsfiddle.net/66z4dxsy/1/

Please disable web security of browser

share|improve this question
    
can you provide your code in jsfiddle ? –  qwertmax yesterday
    
I Already given whole code ..I will try –  Pallavi Sharma yesterday
    
jsfiddle.net/66z4dxsy/1 please disable web security before run fiddle –  Pallavi Sharma yesterday
    
did you try $scope.d=JSON.parse(data); ? –  qwertmax yesterday
    
Why do we need to 'disable security'? As far as instructions/guidance goes, that's a little worrisome. –  David Thomas yesterday

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Browse other questions tagged or ask your own question.