1. Anuncie Aqui ! Entre em contato fdantas@4each.com.br

How to use Observable to emit each value from an array after every 1 second(Angular 5)?

Discussão em 'Angular' iniciado por SijoX, Outubro 9, 2024 às 20:02.

  1. SijoX

    SijoX Guest

    I have a list of Products an array products:product[]

    Using Observable and Observer next method, I want to emit each product to my UI after every 1 second. How can I accomplish this?

    This is what I tried , it is producing an infinite loop.Any help will be much appreciated.

    public streamAllProducts(): Observable<Product> {
    const products = this.ds.getProducts();

    const sequence = new Observable((observer) => {

    products.forEach(element => {


    setTimeout(() => {
    observer.next(element);
    }, 1000
    );
    });


    });
    return sequence;
    }

    Continue reading...

Compartilhe esta Página