2

I am very new to angular 2 I am stuck here where i have to display an image for which I'm using relative path­­­­­­­­­­­­­­­­­­­­

<img src="./../images/publicVideo1.PNG">

but getting the below error

null:1 GET http://localhost:4200/null 404 (Not Found)

enter image description here

The above is the app structure where I have image in images folder which I'm trying to access from public-videos.component.html

I dont understand where I'm wrong Any help would be appreciated.

1
  • i think you should try <img src="./images/publicVideo1.PNG"> if this img is written inside app.componant.html Commented Jun 10, 2017 at 10:52

4 Answers 4

6

create one dir assets in src directory. and move images directory into assets and then you can access image like that. image not found in app folder because we need to set path in assets[] block in the .angular-cli.json. we need set path into asset block we access it. does this help.

<img src="../../assets/images/publicVideo1.PNG">

angular-cli.json

enter image description here

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

Comments

0

Try like this one here

<img [src]="defaultProfilePic" />

and in your component

defaultProfilePic: string ='assets/profile.png';

if this doesn't work it is because of the relative path you used. If you are using visualCode it will help you finding the exact path.

Comments

0

Mention the path relative to your index.html. If your index.html is inside the src folder, then try this:

<img src="./app/images/publicVideo1.PNG">

3 Comments

It isnt coming that way
What is the location of your index.html?
It is in src folder and in app folder level
0

try this <img src="./src/app/images/publicVideo1.PNG">

6 Comments

../ is precisely identical to ./../.
check in the inspect element , open the path in the new tab.
if its not come ,,check like this localhost:4200/src/app/images/publicVideo1.PNG
did you try check in the inspect element? check my above comment
Yes I have checked the inpect element and have opened it i the new tab
|

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.