ngOnInit内でプリロードしてはどうでしょうか。
app.component.ts
typescript
1import { Component ,OnInit} from '@angular/core';
2
3@Component({
4 selector: 'app-root',
5 templateUrl: './app.component.html',
6 styleUrls: ['./app.component.css']
7})
8export class AppComponent implements OnInit {
9 title = 'imagePL';
10
11 isVisible=false;
12
13 img = new Image();
14
15 ngOnInit(){
16 this.img.src="../assets/a.jpg";
17 }
18
19 onClick(){
20 this.isVisible=true;
21 }
22
23}
24
app.component.html
html
1<input type="button" value="click me" (click)="onClick()"/>
2
3<div *ngIf="isVisible">
4 <img src="../assets/a.jpg" />
5</div>
6
バッドをするには、ログインかつ
こちらの条件を満たす必要があります。