2

Why does my image show up as a file logo? link below

This is how my image shows up when I add it

This is my JS for the image (AngularJS)

{
    name: 'Screw',
    price: 1,
    description: 'A small item drilled into objects',
    specs: '1 centimeter',
    images: [
                {
                    full: "1024px-Phillips_screw.jpg"
                }
            ]
}

This is my HTML for adding the image

<img ng-src="{{product.images[0].full}}"/>
3
  • what is the path of the image? check the path. its just a image name Commented Jul 7, 2017 at 16:56
  • Provided Link is broken Commented Jul 7, 2017 at 17:01
  • Check your image full path and compare it with ng-src value. Commented Jul 7, 2017 at 17:19

4 Answers 4

2

Why not use ng-src directive? ie.

<div ng-init="myVar='pic_angular.jpg'">
    <h1>Angular</h1>
    <img ng-src="{{myVar}}">
</div>
Sign up to request clarification or add additional context in comments.

4 Comments

This is the correct way to do this. If you use plain src you will get an extra network call as the browser tries to load the un-interpolated text given in the src and then fire another network request when the text gets interpolated.
You learn something new every day. Thanks @zero298, your answer makes a lot more sense than mine, good stuff!
ok, but if i have multiple images in an array in my app.js file, how would i use a directive in html then? im a bit slow today, sorry about that.
pass them through variables like within the example above
2

Check the console for the error, but it's probably because the path is incorrect.

If they're in your images folder you'd want to put that path:

<img src="/images/{{product.images[0].full}}"/>

3 Comments

This is the incorrect way to do this. Per my comment on swordfish's answer: If you use plain src you will get an extra network call as the browser tries to load the un-interpolated text given in the src and then fire another network request when the text gets interpolated.
@zero298 is right. Thanks for help though William Hampshire
Sure thing @TheWorldSoul. Didn't even occur to me to do it the way swordfish proposed. That's why I love this place!
0

Its passing only name of image into ng-src, you need to write whole path of image where it saved before u pass image name into curly braces.

Comments

0

Your should use absolute or relative path for the image, like

<img src="/images/{{product.images[0].full}}"/>

If you use the latest angularjs 4.x with cli, you need to add the images path to "assets" section in angular-cli.json:

"apps": [ { ......

  "assets": [
    "assets",
    "favicon.ico",
    "images"
  ],
  ........

}

1 Comment

yeah ill use file path, thanks @Blockchain Nerd. Not that comfortable with Ang4 yet haha

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.