您可以使用
scroll
事件来完成此操作:
<mat-dialog-content (scroll)="onScroll($event)">
all your content here...
</mat-dialog-content>
<mat-dialog-actions align="end">
<button [disabled]="buttonDisabled" mat-button>OK</button>
</mat-dialog-actions>
和 TS:
buttonDisabled = true;
onScroll(ev: any) {
if (ev.target.offsetHeight + ev.target.scrollTop >= ev.target.scrollHeight) {
this.buttonDisabled = false;
}
}
在 HTML 中
<mat-dialog-content (scroll)="onScroll($event)">
all your content here...
</mat-dialog-content>
<mat-dialog-actions align="end">
<button [disabled]="buttonDisabled" mat-button>OK</button>
</mat-dialog-actions>
在 TS 中
onScroll(ev: any) {
if (Math.ceil(ev.target.getBoundingClientRect().height) + ev.target.scrollTop >= ev.target.scrollHeight) {
this.data.buttonDisabled = false;
} }
我使用此代码来获取对话框内容的高度
Math.ceil(ev.target.getBoundingClientRect().height