subscribe does not exist on type observable

The name of the pictureThe name of the pictureThe name of the pictureClash Royale CLAN TAG#URR8PPP



subscribe does not exist on type observable<any>



I have upgraded my application from angular 4 to angular 6. I am getting error
subscribe does not exist on type observable . Could somebody tell me if anything has changed in angular 6


import Injectable from '@angular/core';
import Dto, ApiResult from '../api';
import RunsProxy from '../api/proxies';
import Observable, ReplaySubject, Subject from 'rxjs';
import AlertService from './alert.service';
import TranslateService from '@ngx-translate/core';
import ReadonlyProvider from '@wtw/toolkit/src/directives/read-only-inputs.directive';
import Router, NavigationStart, NavigationCancel, NavigationEnd from '@angular/router';
import CurrencyInfo, RunExecution from '../api/dtos';
import tap , map, share, delay from 'rxjs/operators'
import fireAndForget from "platform/tests/helpers";

*public load(id: number): Observable<ApiResult<Dto.RunModel>>
const obs = this._runs.get(id).uiSignal('load run').share();
obs.subscribe(ret =>
if (!!!ret.data && this.blnShown === false)
this.blnShown = true;
this._translate.get('GLOBAL.TOASTS.RUN_UNAVAILABLE').subscribe(o =>
this._alertService.error(o);
);

this._activeRun.next(ret.data);
, err => );
return obs;
*





Possible duplicate of Angular 6: subscribe does not exist on type void
– Swoox
21 hours ago





what was your rxjs version before migrating to angular 6? If it was not 6, then you might want to run following command npm install rxjs@6 rxjs-compat@6 --save and save rxjs-compact
– Rajeev Ranjan
21 hours ago


npm install rxjs@6 rxjs-compat@6 --save





Hello Rajeev, I don't want the install rxjs-compat and go that route. Instead want to change my code to work with the new version . It was version 4 and now 6
– Tom
20 hours ago




1 Answer
1



Here is an example of my service. You can put same code as per your requirement.



My Service


import Injectable from '@angular/core';
import Http, Response, Headers, RequestOptions from '@angular/http';
import Observable, of from 'rxjs';
import map, catchError from 'rxjs/operators';

@Injectable(
providedIn: 'root'
)

export class PollSerivce

constructor(private _http: Http)

getPollPostData(url: any)
const options = new RequestOptions( withCredentials: true );
return this._http.get(url)
.pipe(
catchError(this.handleError)
);


private handleError(error: Response)
console.error(error);
return Observable.throw(error.json().error



My Component file


getDataSource()
this._pollSubscription = this.pollSerivce.getPollPostData(StaticKeywords.baseUrl).subscribe(response =>
this.pollPostData = response.json().hits;
,
err =>
console.log(err);
);



There are many changes in rxjs 6 so if you want to learn more about it you can check this websites ::



https://auth0.com/blog/whats-new-in-rxjs-6/
https://www.academind.com/learn/javascript/rxjs-6-what-changed/
https://www.learnrxjs.io/concepts/rxjs5-6.html






By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

Popular posts from this blog

Firebase Auth - with Email and Password - Check user already registered

Dynamically update html content plain JS

How to determine optimal route across keyboard