Angular: ngIf="returnsPromise() | async" goes to infinite loop

Created on 26 Jan 2016  路  3Comments  路  Source: angular/angular

I was experimenting with AsyncPipe that this happened. If a method is returning a promise and you pipe it to AsyncPipe it will go to infinite loop and crashes the browser.

screen shot 2016-01-25 at 8 45 42 pm

_Sorry for screenshot, tab was frozen and I couldn't copy the code_

Most helpful comment

this is expected behavior, because each time the method is called, you're returning a new instance of the promise, which when resolved, triggers change detection, which retrieves a new promise, which triggers change detection....

You should a) generally avoid calling methods from the view and b) assign a promise to a property

All 3 comments

this is expected behavior, because each time the method is called, you're returning a new instance of the promise, which when resolved, triggers change detection, which retrieves a new promise, which triggers change detection....

You should a) generally avoid calling methods from the view and b) assign a promise to a property

@robwormald The example given in the docs describes piping a promise to AsyncPipe.

Should those docs be updated?

Source Docs

angular.io

This issue has been automatically locked due to inactivity.
Please file a new issue if you are encountering a similar or related problem.

Read more about our automatic conversation locking policy.

_This action has been performed automatically by a bot._

Was this page helpful?
0 / 5 - 0 ratings