2

I am creating a project in Angular 4 using Visual studio code. How can we add images(local image on my desktop) in the Visual studio code and display in the view?(we can create a model and display the image by the SRC tag but that works for the image hosted in some server).

If we cant add the images in Visual studio code then how do we render the local images on the view?

Please help

2 Answers 2

2

Possible duplicate:

How to load image (and other assets) in Angular an project?

In my project I am using the following syntax in my app.component.html:

<img src="assets/img/1.jpg" alt="image">

or

<img src='http://mruanova.com/img/1.jpg' alt='image'>

use [src] as a template expression when you are binding a property using interpolation:

<img [src]="imagePath" />

is the same as:

<img src={{imagePath}} />

Source: how to bind img src in angular 2 in ngFor?

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

1 Comment

I copied and pasted my own answer from a previous question to save you one click.
1

Visual studio code cannot store the image for the Angular application. It is just an editor like notepad with advanced features to make coding a pleasurable experience.

You could place your image in the folder where you have the package.json file and you could display the image in your app by replacing the web url with just the image name.

Of course it is better to create a separate folder for images and use the absolute/relative path in your code where you are using the images.

Hope that helps.

Comments

Your Answer

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