0

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?

2
  • what exactly do you mean by "make AngularJS block"? When I am asynchronously requesting data, I typically set a $scope.loading = true; flag in the controller and in the promise's finally() function, I set $scope.loading = false;. In my templates I would use something like: ng-if="!loading" or ng-show="!loading" Commented Aug 28, 2016 at 22:00
  • plong0: that sounds like a usable system... but if you wouldn't mind making a super small example at plunkr where it just waits 1 second before populating the AngularJS fields that would be really awesome! Commented Aug 28, 2016 at 22:05

1 Answer 1

1

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.

Sign up to request clarification or add additional context in comments.

1 Comment

Thank you! This is exactly what I was looking for!

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.