Encountering an error in my Angular application that reads:
ERROR TypeError: rxjs_Observable__WEBPACK_IMPORTED_MODULE_4__.Observable.timer is not a function at SwitchMapSubscriber.project (hybrid.effect.ts:20) at SwitchMapSubscriber.push../node_modules/rxjs/_esm5/internal/operators/switchMap.js.SwitchMapSubscriber._next (switchMap.js:34) at SwitchMapSubscriber.push../node_modules/rxjs/_esm5/internal/Subscriber.js.Subscriber.next (Subscriber.js:54) at FilterSubscriber.push../node_modules/rxjs/_esm5/internal/operators/filter.js.FilterSubscriber._next (filter.js:38) at FilterSubscriber.push../node_modules/rxjs/_esm5/internal/Subscriber.js.Subscriber.next (Subscriber.js:54) at ScannedActionsSubject.push../node_modules/rxjs/_esm5/internal/Subject.js.Subject.next (Subject.js:47) at SafeSubscriber._next (store.js:332) at SafeSubscriber.push../node_modules/rxjs/_esm5/internal/Subscriber.js.SafeSubscriber.__tryOrUnsub (Subscriber.js:195) at SafeSubscriber.push../node_modules/rxjs/_esm5/internal/Subscriber.js.SafeSubscriber.next (Subscriber.js:133) at Subscriber.push../node_modules/rxjs/_esm5/internal/Subscriber.js.Subscriber._next (Subscriber.js:77)
Snippet of the code triggering this error:
import { Injectable } from '@angular/core';
import { Effect, Actions } from '@ngrx/effects';
import { of } from 'rxjs/observable/of';
import { map, catchError, switchMap } from 'rxjs/operators';
import { Observable } from 'rxjs/Observable';
import **'rxjs/add/observable/timer';**
import * as hybridActions from '../actions/hybrid.action';
import { FleetStatusReportService } from '../../fleet-status-report.service';
@Injectable()
export class HybridEffects {
constructor(
private actions$: Actions,
private fleetstatusreportService: FleetStatusReportService
) {}
@Effect()
loadHybrid$ = this.actions$.ofType(hybridActions.LOAD_HYBRID).pipe(
switchMap(() => Observable.timer(0, 900000)),
switchMap(() => {
return this.fleetstatusreportService.getHybridPerformance().pipe(
map(hybrid => new hybridActions.LoadHybridSuccess(hybrid)),
catchError(error => of(new hybridActions.LoadHybridFail(error)))
);
})
);
}
After researching online, it seems that the latest Angular version should use
**import 'rxjs/add/observable/timer';**
However, this solution doesn't work for me. Any guidance on how to resolve this issue would be appreciated.