如何在角度2中为模态弹出窗口设置宽度和高度

时间:2018-08-20 06:54:05

标签: angular angular6

我正在尝试将高度和宽度设置为模态。我该怎么办?

方式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>

1 个答案:

答案 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>

示例:https://stackblitz.com/edit/angular-rdjxwy