Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

rxjs: Observable.of(...).delay is not a function

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"
like image 452
Dániel Kis Avatar asked Feb 16 '18 12:02

Dániel Kis


2 Answers

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';
like image 107
toskv Avatar answered Oct 23 '22 16:10

toskv


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) );
like image 41
Francesco Avatar answered Oct 23 '22 16:10

Francesco