I would like to create a delayed observable in typescript by:
import 'rxjs/add/observable/of';
...
const o = Observable.of(values).delay(10000);
o.subscribe((v) => { alert(v); });
but I got the following error:
"Observable_1.Observable.of(...).delay is not a function"
In rxjs6 operators can be found in the 'rxjs/operators/*' packages.
import { delay } from 'rxjs/operators/delay';
of(values).pipe(
delay(1000)
).subscribe(console.log);
In older versions can import the delay operator separately.
import 'rxjs/add/operator/delay';
In rxjs 6 this works fine:
import { Observable, of } from 'rxjs';
import { delay } from 'rxjs/operators';
...
const o = of(values).pipe(
delay(10000)
);
o.subscribe( v => alert(v) );
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With