1

Using AngularJS it was possible displaying images like this:

ng-src="public/img/{{item.image}}" 

Where {{item.image}} is stored in MongoDB.

My question therefore is pretty straightforward... How would I achieve the same thing in Angular 4?

3 Answers 3

4

Something like this:

<img src = "public/img/{{item.image}}">

Or alternatively as Pankaj pointed out:

<img [src] = "'public/img/' + item.image">

There is a chapter in the Angular docs that map AngularJS features to Angular features that may be helpful:

https://angular.io/guide/ajs-quick-reference#ng-src

Sign up to request clarification or add additional context in comments.

2 Comments

I know you must have mistakenly missed it. You might want to do like [src]="'public/img/'+item.image"?
Yea, I just cut and pasted his right hand side. So my original answer is not actually correct. I'll update it. THANKS!
1

With either of these :

<img src="public/img/{{item.image}}" />
<img [src]="'public/img/'+item.image" />

Comments

0

Something like this works as well:

<img [src] = `public/img/${item.image}`>

Use backticks instead of single or double quotes and ${variable_name}.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.