我正在尝试将高度和宽度设置为模态。我该怎么办?
方式1:
<button (click)="showDialog = !showDialog" class="btn">Open</button>
<app-dialog [(visible)]="showDialog" [height]="200" [width]="250">
<h1>Hello World</h1>
<button (click)="showDialog = !showDialog" class="btn">Close</button>
</app-dialog>
答案 0 :(得分:1)
添加Input属性绑定以向对话框添加动态宽度
<app-dialog [height]="200" [width]="200" [(visible)]="showDialog">
<h1>Hello World</h1>
<button (click)="showDialog = !showDialog" class="btn">Close</button>
</app-dialog>
dialog.html
<div [@dialog] *ngIf="visible" class="dialog" [ngStyle]="{width:width+'px',height:height+'px'}">
<ng-content></ng-content>
<button *ngIf="closable" (click)="close()" aria-label="Close" class="dialog__close-btn">X</button>
</div>
<div *ngIf="visible" class="overlay" (click)="close()"></div>