Vinod
Vinod

Reputation: 1290

Module '/node_modules/rxjs/observable/TimerObservable' has no exported member 'TimerObservable' in Angular 6

While migrating application from Angular 5 to Angular 6 getting below error,

Module '/node_modules/rxjs/observable/TimerObservable' has no exported member 'TimerObservable'.

Code:

import { Injectable } from '@angular/core';
import { TimerObservable } from 'rxjs/observable/TimerObservable';
import { Observable } from 'rxjs';

@Injectable()
export class TimerTestScv {

    static fetchTimer(interval: number, initialDelay: number): Observable<number>         
    {
       return TimerObservable.create(initialDelay, interval);
    }
}

rxjs package used:

"rxjs": "^6.2.2",

Upvotes: 3

Views: 1998

Answers (2)

Andy Southwell
Andy Southwell

Reputation: 93

From RxJS 6 onwards, TimerObservable has been replaced with timer. Use the following as a replacement:

import { timer } from 'rxjs';

// start at time 1s and tick every 2s
let myTimer = timer(1000, 2000);

const subscription = myTimer.subscribe(() => {
    /* Do stuff here */
})
...
subscription.unsubscribe()

Upvotes: 3

Serhii Vasko
Serhii Vasko

Reputation: 443

Use timer instead of TimerObservable

All observable classes (https://github.com/ReactiveX/rxjs/tree/5.5.8/src/observable) have been removed from v6, in favor of existing or new operators that perform the same operations as the class methods.

Upvotes: 1

Related Questions