alidrongo alidrongo - 2 months ago 6x
AngularJS Question

Angular printing out $scope function instead of returning value (when called from DOM)

I'm trying to load an image from Google Drive into an image elemnent in my Angular application:

<div >
<div ng-repeat="attachment in event.attachments">
<img src="{{getImage(attachment.fileId)}}"/>

The code in my controller:

$scope.getImage = function(fileId){
return ''+fileId;

When I run the code the request URL show that the function name is being printed out instead of returning the image URL. Here is the request:


Can anyone help me to get the image to load?



Use ng-src to wait for the interpolation to take place, like this:

<img ng-src="{{getImage(attachment.fileId)}}"/>

More on ng-src here.