I have 2 sibling component having a service which has HTTP call to render a json. OnInit, the Component B fetches the HTTP response calling the service and loads the screen. The click event on the Component A, should make the component B to refresh its data.
I followed the answer posted by ObjectiveTC from -> What is the correct way to share the result of an Angular 2 Http network call in RxJs 5?
_docdata: BehaviorSubject<DetailSection[]> = new BehaviorSubject<DetailSection[]>([]);
service.getData(){return this.http.get(this.url)
.map((res) =>{this._docdata = (res.json()); console.log("1st return"); return this._docdata; })
.catch((error:any) => Observable.throw(error|| 'Server error')); }
This worked fine.
refresh(){
this.http.get("../../assets/reqd-detail.json")
.map(res => res.json())
.subscribe((data:Array<DetailSection>) => this._docdata.next(data));
}
getting error --> ERROR TypeError: _this._docdata.next is not a function at SafeSubscriber._next (detail.service.ts:156) at SafeSubscriber.webpackJsonp.../../../../rxjs/Subscriber.js.SafeSubscriber.__tryOrUnsub (Subscriber.js:238) at SafeSubscriber.webpackJsonp.../../../../rxjs/Subscriber.js.SafeSubscriber.next (Subscriber.js:185) at Subscriber.webpackJsonp.../../../../rxjs/Subscriber.js.Subscriber._next (Subscriber.js:125) at Subscriber.webpackJsonp.../../../../rxjs/Subscriber.js.Subscriber.next (