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); });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); // ^^^^^^^^^^^^ ^ }