Say I have the following method used to retreive all the "year" from an array of object and then get the distinct value:
public getYears(): Observable<number[]>
{
return Observable.from(this.payments.map(p => p.year)).distinct().toArray();
}
And elsewhere in my code, I use it like this:
this.getYears().subscribe(years => this.yearsRefinement = years);
Is it enough to do this or is it better to do:
let sub = this.getYears().subscribe(years => this.yearsRefinement = years);
sub.unsubscribe();
I really struggle knowing when I have to unsubcribe or not from an observable. From what I understand, this observable is "finite", so once I get the value, it's completed, so it's not required to unsubscribe from it. Is it correct?