Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

how to append web service json data every time when function is called using angularjs

Here i am calling function getData at every second all is happning good except appending. every time when function is calling the angularjs is replacing old data to new data. but i want to append after existing data. any one plz help.

     <div ng-app="serviceConsumer">
     <div ng-controller="questionsController">
    <div ng-repeat="j in LiveChat">
    <div>
    <div>{{j.UserName2}}</div>
    <div>
    <div>{{j.Text2}}<div>
    </div>
    </div>
    </div>
    </div>
    </div>
    </div>
    </div>
    <script>
    var app = angular.module('serviceConsumer', []);
    app.controller('questionsController', function ($scope, $http) {
    $scope.getData = function () {
            $http({
                method: "GET",
                url: "/GetUserDataWebServices.asmx/GetLiveChatListData",
                params: {
                    username: $('.ExeCutiveName').text()
                }
            })
             .success(function (data) {
                 var myjson = JSON.parse(data);
                 $scope.LiveChat = JSON.parse(myjson);
                 //here i want to append myjson to existing ng-repeat <div>
             });
        }
    )};
    setInterval($scope.getData, 1000);
    </script>
like image 535
Nitesh Avatar asked Dec 12 '25 21:12

Nitesh


1 Answers

You need to use push method

like $scope.LiveChat.push(JSON.parse(myjson));

like image 130
Rohan Kawade Avatar answered Dec 15 '25 10:12

Rohan Kawade