【问题标题】:Angular 7 problem with component to show image on html. Why isn't the image showing?Angular 7 组件在 html 上显示图像的问题。为什么图片不显示?
【发布时间】:2020-11-22 02:05:14
【问题描述】:

我在做一个点击猫游戏,当我用img把猫图片的路径放到组件的模板中时,运行页面时图片没有出现。

我尝试使用 [img]="path" 将 img 作为属性,并直接输入到 img 元素的路径

模板:

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

打字稿

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

【问题讨论】:

标签: html angular image typescript angular6


【解决方案1】:

您的代码一切正常。

只需将图片文件夹从

/src/app/image

/src/assets

目录并更改src in

app.component.html

【讨论】:

    猜你喜欢
    • 2012-06-11
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2021-03-06
    相关资源
    最近更新 更多