Angular 2 Binding to a function on the view results to infinite calls to the data service
I'm trying to bind a src attribute of images inside an ngFor directive that looks like this: <div *ngFor="imageId of imageIds"> <img [attr.src]="imageSrc(imageId)" alt="{{imageId}}"> </div> the imageSrc method inside the component looks like this: imageSrc(imageId: string){ var hostUrl = "http://192.168.0.101:3000/"; var imageUrl = hostUrl+"images/"+imageId; var imgSrc = ""; this._imageService.getImage(imageId) .subscribe(image => { imgSrc = hostUrl + image.url }); return imgSrc; } The getImage function in the Injectable ImageService looks like this: getImage(id: string) { var _imageUrl =