What is the problem when I return a promise from angular service
instead of Observable?
If it's a matter of any manipulation or side-effect, that I can easily do inside angular service itself. Then why I shouldn't return a promise over observable?
Here's my code for service class
public async getCountriesAsync(filter: PaginateFilter): Promise<Paginate<IdNameTypeModel>> {
return await this.http.get<Paginate<IdNameTypeModel>>(`/api/{version}/Types/{lang}/Countries${filter.url()}`)
.pipe(map(response => {
return response == null ? new Paginate<IdNameTypeModel>() : response;
})).toPromise();
}
Using inside component
async loadCountries() {
const filter = new PaginateFilter(this.data.pageIndex, this.data.pageSize);
this.countries = await this.dldTypesService.getCountriesAsync(filter);
}
response == null
will betrue
ifresponse = undefined
as well. \$\endgroup\$