I want to read the App.net public stream. However when I use a simple $http.get() I only get one response.
$http
.get('https://alpha-api.app.net/stream/0/posts/stream/global')
.success(function (results) {
console.log('received results', results);
})
;
How do I connect to http streams in AngularJS?
Is there even a way or would I have to use something like WebSockets?
$http is a single request only. For long polling, call it periodically with $interval.
function MyCtrl($scope, $timeout) {
function poll() {
$http.get('...').success(function(data) {
$scope.posts = data;
});
$timeout(poll, 10000);
}
poll();
}
You could also create a service to encapsulate this logic, but you would need a fixed data structure to be updated, instead of changing the result. Something like this.