Bala Krishna
Bala Krishna

Reputation: 39

For the first time button click it is not binding data into table,

For the first time button click it is not binding data into table, again after second click it is getting bound. I need the data to be bound for first click

var resturant=angular.module('resturantmodule',[]);
resturant.controller('resturantcontroller',function($scope,$http){

    $scope.resturants=[];
    $scope.onResturantClick=function(){

        var url="https://query.yahooapis.com/v1/public/yql?q=select%20*%20from%20local.search%20where%20zip='"+$scope.pin +"'and%20query='"+$scope.order +"'&format=json&diagnostics=false&callback=";

        $http.get(url).success(function(data){
        $scope.resturants.push(data);


        if(data){

            var len = data.query.results.Result.length;           
            var txt = "";
            if(len > 0){                 
                for(var i=0;i<len;i++){

                    if(true){                    
                        txt += "<tr><td>"+data.query.results.Result[i].Title+"</td><td>"+data.query.results.Result[i].Title+"</td></tr>";                      

                    }
                }               
                if(txt != ""){          


                    var tbody = document.querySelector("#list tbody");                    
                    tbody.appendChild(tbody.innerHTML=txt);
                   // tbody.innerHTML=txt;
                    //alert(txt);
                    //tr.innerHTML = txt;
                   // tbody.appendChild(tbody)


                }
            }
        }

        });
    }

});

Upvotes: 0

Views: 104

Answers (1)

Bala Krishna
Bala Krishna

Reputation: 39

by using below functions we can bind data from javascript to html table

var tbody = document.querySelector("#list tbody"); //Add Table ID tbody.appendChild(tbody.innerHTML=txt);

Upvotes: 1

Related Questions