Currently have a scenario where a method within a shared service is used by multiple components. This method makes an HTTP call to an endpoint that will always have the same
Late to the party, but I created a reusable decorator specifically to address this use-case. How does it compare to the other solutions posted here?
when exactly you want to share the underlying observable (see docs).It's published under an umbrella I'll be using for various Angular-related utilities.
Install it:
npm install @ngspot/rxjs --save-dev
Use it:
import { Share } from '@ngspot/rxjs/decorators';
class SharedService {
constructor(private http: HttpClient) {}
@Share()
getSomeData(): Observable {
return this.http.get('some/endpoint');
}
}