M
M
Maria2020-10-30 18:02:13
Angular
Maria, 2020-10-30 18:02:13

Why doesn't Angular's async pipe work with a getter that returns a Promise?

Why doesn't Angular's async pipe work with a getter that returns a Promise?

.ts component:

get user(): Promise<string> {
     //метод возвращающий промис
    return getCurrentUser();
  }


Component .html - in html this thing returns nothing, just an empty string Why does this happen? What could be the problem? PS. If in the constructor we wait for the resolution of the promise and in then assign the result to user and display in html simply user as a string without an async pipe, then everything works without problems. Those. getCurrentUser() method works correctly
<p>{{ user | async }}</p>

user | async


Answer the question

In order to leave comments, you need to log in

1 answer(s)
A
Anton Shvets, 2020-10-30
@missbells

If you do this, then for each check of the change, Angular will start the promise again. If you have a network request, check that you do not have a million canceled requests there.
It would be necessary not through a getter, but to transfer a promise to a variable.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question