Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Property 'delay' does not exist on type 'Observable<string[]>'

After upgrading to angular6 fews problem while using rxjs

import {
  Observable,
  Subject,
  asapScheduler,
  pipe,
  of,
  from,
  interval,
  merge,
  fromEvent
} from "rxjs";

import { delay } from "rxjs/operators";

let obser = from([ 1, 2, 3 ]).delay( 3000 );

Getting Property 'delay' does not exist on type 'Observable'

on angular 5 this works fine

  import { Observable } from 'rxjs/Observable';
  let obser = Observable.from([ 1, 2, 3 ]).delay(3000);
like image 967
Pascal Avatar asked Jul 20 '18 05:07

Pascal


2 Answers

Angular 6 comes with rxjs 6 which have some differencies. In rxjs 6 you chain operators via pipe:

let obser = from([ 1, 2, 3 ])
    .pipe(
        delay( 3000 )
    );
like image 125
belicam Avatar answered Sep 18 '22 15:09

belicam


I am in angular 9 and still 'delay' is not resolved in rxjs 6.*.

import { delay } from 'delay from rxjs/internal/operators';

Here is a quick example code using delay in a mock service:

import { Injectable } from '@angular/core';
import { Observable, of } from 'rxjs';
import { delay } from 'rxjs/internal/operators';

@Injectable()
export class AppService {
  fetchData(): Observable<string> {
    return of('Todo')
    .pipe (
      delay( 1000 )
    );
  }
}
like image 40
Jai Berman Avatar answered Sep 22 '22 15:09

Jai Berman