3

I'm getting into Angular 2 and webpack and I'm a little confused about how to reference images using file-loader. As far as I can tell, that you cannot directly put a require() in your html like this:

<img src="require('./abc.png')">

The only way I was able to get this to work was to create a class member and reference it the html.

my.component.ts:

@Component({
    selector: 'my-comp',
    template: require('./comp.template.html')
})
export class LoginComponent {
    private myImg: string = require('./abc.png');
}

html:

<img [src]="myImg">

Is this how you're expected to use file-loader with images?

d512
  • 32,267
  • 28
  • 81
  • 107
  • Check here: [How to use webpack for image loading](http://stackoverflow.com/questions/37671342/how-to-load-image-files-with-webpack-file-loader) – vgoreiko Feb 20 '17 at 20:40

0 Answers0