rxjs take operator is not working correctly

Discussão em 'Angular' iniciado por Brett Old, Novembro 25, 2024.

  1. Brett Old

    Brett Old Guest

    I am going to set first item's id as selected id in the initial loading. For this, I used rxjs take operator, but it is not working. Please help me find why it is not working.

    ngOnInit(): void {
    this.store.dispatch(new LoadVariantsBatch());

    this.filteredVariants$.pipe(take(1)).subscribe((variants) => {
    console.log(variants.length);
    if (variants.length > 0) {
    this.onSelectVariant(variants[0].id);
    }
    });
    }


    I used take(1), but when I log items length, it shows 5 which is the length of the whole item list.

    Continue reading...

Compartilhe esta Página