【发布时间】:2018-03-16 10:09:27
【问题描述】:
所以我正在尝试制作一个基本网站,并且在单击按钮时需要显示图像。问题是它向我显示了图像,但是当我单击另一个按钮向我显示另一个图像时,先前的图像仍然存在。 这是我的代码。我正在使用 Angular 4 和打字稿。
组件.ts
openPredictionImg() {
const myImg = new Image();
myImg.useMap = '../../assets/prediction.png';
const img = document.createElement('img');
document.body.appendChild(img);
img.setAttribute('src', myImg.useMap);
img.onload = (stop);}
openRebalancingImg() {
const myImg = new Image();
myImg.useMap = '../../assets/rebalancing.png';
const img = document.createElement('img');
document.body.appendChild(img);
img.setAttribute('src', myImg.useMap);
img.onload = (stop);}
openVisualizationImg() {
const myImg = new Image();
myImg.useMap = '../../assets/visualization.png';
const img = document.createElement('img');
document.body.appendChild(img);
img.setAttribute('src', myImg.useMap);
img.onload = (stop);}
component.html
<button class="predictionBtn "(click)="openPredictionImg()" style="width: 10%">Prediction</button>
<button class="rebalancingBtn" (click)="openRebalancingImg()" style="width: 10%">Rebalancing</button>
<button class="visualizationBtn" (click)="openVisualizationImg()" style="width: 10%">Visualization</button>
【问题讨论】:
标签: html angular typescript