Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

303
Views
@ngrx/store: la tienda no devuelve los datos de manera asíncrona/ausente

Tengo un problema al obtener el valor de la tienda. La operación se cuelga. Intento obtener los datos de la siguiente manera:

 async onInit(params: Params) { // it hangs on the line bellow var userToken = await this.store.select(fromRoot.getUserToken).toPromise(); console.log(userToken); }

luego ejecuto la siguiente función asíncrona:

 ngOnInit(): void { this.route.params.subscribe(params => { this.onInit(params).then(() => console.log('promise executed')); });

El token de usuario nunca se devuelve.

Si me suscribo a la tienda, entonces funciona bien.

 this.store.select(fromRoot.getUserToken).subscribe(ut => { console.log(ut); });
about 4 years ago · Santiago Trujillo
1 answers
Answer question

0

Recientemente también tuve este problema. Como @ maxime1992 indica que necesita un operador para finalizar el observable.

 async onInit(params: Params) { // it hangs on the line bellow const userToken = await this.store.select(fromRoot.getUserToken).pipe(take(1)).toPromise(); console.log(userToken); // ^^^^^^^^^^^^^^ }

Actualización para rxjs 7+, ahora usamos firstValueFrom o lastValueFrom:

 async onInit(params: Params) { // it hangs on the line bellow const userToken = await firstValueFrom(this.store.select(fromRoot.getUserToken).pipe(take(1))); console.log(userToken); // ^^^^^^^^^^^^ ^ }
about 4 years ago · Santiago Trujillo Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!