I use Observable in my Angular 4 application to load data from a web api.
Have a service that looks like this:
import { Injectable, Output, EventEmitter } from '@angular/core';
import { Http } from '@angular/http';
@Injectable()
export class WorkgroupsService {
constructor(private _http: Http) {
}
getWorkgroups() {
return this._http.get(`/api/security/getsecurityworkgroups`).map(res => res.json());
}
}
And use it something like this:
loadWorkgroups() {
this._workgroupsService.getWorkgroups()
.subscribe((workgroups: any) => {
this.workgroups = workgroups;
});
}
Whenever the api returns an error it creates an infinite loop, the request is sent over and over again.
How can I stop it?
Thanks!