Dániel Kis
Dániel Kis

Reputation: 2631

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"

Upvotes: 10

Views: 9217

Answers (2)

toskv
toskv

Reputation: 31600

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';

Upvotes: 15

Francesco
Francesco

Reputation: 435

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) );

Upvotes: 3

Related Questions