How to Update Model in AngularJS when Ajax used Long Polling?

How to update the model when i used ajax long polling technique? At first i will load the default list

Example: - id1 - id2 - id3

Then in my background process, i setup a ajax long polling that will run every 5seconds interval. When the ajax receive an update it will update the display in angularjs accordingly without refreshing page.

So from the example below, when i receive changes, it should output something like this: Example: - id1 - im New Here.. - id3

Is that possible using this technique?.. without using any websocket or nodejs...

Thanks

Yes it's possible.

I assume you want to do a GET request every 5 seconds so not really keeping your connection open constantly.

If you place the request method inside your scope you could do something like this:

$scope.ids = ['id1','id2','id'3]; //by initial request.

postFunction() {
    //Request here
    var newData = request.data;
    $scope.ids.push(newData);
}

Since Angular modals use 2way databinding your html gets updated instantly.