florianzobele:
I have to get datas from to Subscribe but I get always data of the first one.
I have a data shared service :
import { Injectable } from '@angular/core';
import { BehaviorSubject } from 'rxjs/BehaviorSubject';
@Injectable()
export class DataService {
private source = new BehaviorSubject('');
data = this.source.asObservable();
constructor() { }
update(values: any) {
this.source.next(values);
}
}
Before leaving search component, I call update method.
Now, I'm on the results component. I get shared data like that :
constructor(private dataSvc: DataService,
private router: Router,
private rideStore: RideStore) { }
ngOnInit() {
this.getData();
}
getData() {
this.subscription = this.dataSvc.data.take(1).subscribe(
data => this.data = data ? data : undefined,
err => console.log(err),
() => this._isValid()
);
}
My question is : I need shared data to subscribe to another Observable. First, I construct an object ride and after i call the search method
search() {
this.rideStore.searchRides(this.ride).subscribe(
rides => {
// this.dataSvc.update(rides);
this.rides = rides;
console.log('results', this.ride);
},
err => console.log('err', err)
);
}
The problem is I always get data from data service and not from the api call. The api works cause I intercept results in store but not in the component. So How I can stop subscribing first observable and subscribe of the second ?
Posted in S.E.F
via StackOverflow & StackExchange Atomic Web Robots
This Question have been answered
HERE