I have a problem where Angular2 makes the same request twice. I don't know why, though, because I have only one time a subscribe on the Observable. Here is my code:
My service looks like this:
getProjects(): Observable<Project[]> {
return this.http.get(this.url)
.map(this.mapProjects)
.catch(this.handleError);
}
private mapProjects(response: Response): any {
const mappedProjects = response.json();
return mappedProjects;
}
My component looks like this:
export class ProjectListComponent implements OnInit {
// List of projects
listProjects: Project[] = [];
constructor(private projectListService: ProjectListService) {
}
public getProjectList() {
this.projectListService.getProjects()
.subscribe(
projects => {
this.listProjects = projects;
},
error => {
// error handling
});
}
}
In the network tab of the Chrome Developer Tools I see the request is made two times, once the initiator is zone.js, the other time it just says "Other". Can anyone explain this behaviour?