clearairturbulence clearairturbulence - 1 year ago 83
AngularJS Question

How to make AngularJS wait for more data?

I want to use a websocket to get information once AngularJS is loaded, and then apply the new data to the template transformations. Is there a way to make AngularJS block while new data is being requested?

Answer Source

I typically use an approach where before making the async call, I set a $scope.loading = true; and in the promise's finally() callback, I set $scope.loading = false; With this flag set, it is very easy to use any of ng-switch/ng-show/ng-if to toggle visibility of elements in the template.

I have prepared a plunker demo showing this approach.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download