user6072343
user6072343

Reputation:

Angular 2 Image not showing

So I have a very basic issue.

Images are not showing in my Angular 2 application.

This is how I define an image:

<img alt="logo" [src]="'./images/logo.png'">

Is there a package I'm supposed to install to make images work?

BTW I'm new to Angular as you can probably guess!

Upvotes: 0

Views: 4047

Answers (3)

lanetrotro
lanetrotro

Reputation: 357

you need to install an image loader

Try file-loader then you should add in your webpack this rules

    module.exports = {
  module: {
    rules: [
      {
        test: /\.(png|jpg|gif)$/,
        use: [
          {
            loader: 'file-loader',
            options: {}  
          }
        ]
      }
    ]
  }
}

it should work now

Upvotes: 0

RajAnkathi
RajAnkathi

Reputation: 11

Property binding ('[]') : To set a property of a view element to the value of a template expression.

<img alt="logo" src="'./images/logo.png'">

just works fine

Upvotes: 1

snorkpete
snorkpete

Reputation: 14574

If your image url is a known value as you seem to be indicating here, there's no need for any special angular property binding.

Simply specify your image tag using normal HTML:

<img alt="logo" src="images/logo.png">

Note that the path above is a relative path

Upvotes: 0

Related Questions