I need to dynamically change the img src by calling a function that returns the image path, but when I use the code below, the image element shows as <img src(unknown)/>
component.ts:
getMedia(row) {
this.sharedDataService.inventoryRows.forEach(function(elem){
if(row.vin === elem.vin){
console.log(elem.media[0].href); //logs string correctly
return elem.media[0].href;
}
});
}
this code successfully logs the string stored in elem.media[0].href to the console, so I'm confident it is returning the correct path as a string.
HTML:
<img src="{{getMedia(row)}}" />
//DOM element comes back as <img src(unknown)/>
I've also tried the following, as suggested by other Stackoverflow answers, but I don't get the desired DOM element using this either
<img [src]="getMedia(row)" />
//DOM element comes back as <img src="null"/>
I'm certain that this should be possible, but I'm clearly missing some behind-the-scenes knowledge about its inner workings
this.sharedDataService.inventoryRowsan async operation? Can you provide that code as well?rowthat you are passing as an argument from the html?