简体   繁体   English

Angular 2图片未显示

[英]Angular 2 Image not showing

So I have a very basic issue. 所以我有一个非常基本的问题。

Images are not showing in my Angular 2 application. 图像未显示在我的Angular 2应用程序中。

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! 顺便说一句,您可能会猜到我对Angular是陌生的!

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 很好

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: 只需使用常规HTML指定图像标签:

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

Note that the path above is a relative path 请注意,上面的路径是相对路径

you need to install an image loader 您需要安装图像加载器

Try file-loader then you should add in your webpack this rules 尝试使用文件加载器,那么您应该在Webpack中添加此规则

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

it should work now 它现在应该工作

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM