I have this service to share data between components of my application :
import { Injectable } from '@angular/core';
import { BehaviorSubject } from 'rxjs/BehaviorSubject';
@Injectable()
export class DataService {
private source = new BehaviorSubject<any>('');
data = this.source.asObservable();
constructor() { }
update(values: any) {
this.source.next(values);
}
}
From a component, I update data like this :
this.dataSvc.update(this.data);
Assuming this.data is an object.
From another component, I subscribe at the service
this.dataSvc.data.subscribe(
data => let object = data,
error => console.log(error),
() => console.log('complete')
);
The complete method is never called.
How I can call the complete method and stop subscribing ?
I tried to add this.source.complete() just after next in service. It doesn't work
Thanks
this.dataSvc.data.take(1).subscribe(...)- Sasxaimport 'rxjs/add/operator/take'- AJT82