简体   繁体   English

在 html 上显示图像的组件的 Angular 7 问题。 为什么图片不显示?

[英]Angular 7 problem with component to show image on html. Why isn't the image showing?

I am doing a click cat game, and when I put the path of the image of the cat in the component's template using img, the image does not appear when running the page.我在做一个点击猫游戏,当我使用img将猫的图像的路径放在组件的模板中时,运行页面时没有出现图像。

I tried to use the img as property using [img]="path", and also enter the path directly to the img element我尝试使用 [img]="path" 将 img 用作属性,并且还直接输入到 img 元素的路径

Template:模板:

<div>{{catName1}}</div>
<div>
    <img src="./image/cat.jpg" (click)="clickUp()">
</div>
<div>{{catClick1}}</div>
</div>

Typescript打字稿

import { Component } from '@angular/core';

@Component({
 selector: 'app-root',
 templateUrl: './app.component.html',
 styleUrls: ['./app.component.css']
})
export class AppComponent {

  catName1 = 'Misho';
  catImg1 = 'image/cat.jpg';
  catClick1 = 0;

  clickUp(){
    this.catClick1 += 1;
  }

} 

How it is showing它是如何显示的

Folder of the image图片的文件夹

Everything's fine with your code.您的代码一切正常。

Just move your image folder from只需将您的图像文件夹从

/src/app/image

to

/src/assets

directory & do change the src in目录并更改src

app.component.html应用程序组件.html

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

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