我有一个MatDialog
(with MatDialogContent
),它比屏幕大,所以会出现竖线。在不成功的提交和所有表单的字段重新验证之后,我想有条件地滚动到该对话框的底部,以显示MatError
给用户。如何做到这一点?
问问题
51 次
1 回答
1
我以编程方式在 div 上实现了滚动,但不确定 MatDialogContent 但你可以试一试。
<div #scrollMe style="overflow: scroll; height: xyz;">
// ...Scroling content
</div>
然后在 component.ts
import {..., ElementRef, ViewChild, OnInit} from 'angular2/core'
@Component({
...
})
export class ChannelComponent implements OnInit{
@ViewChild('scrollMe') private myScrollContainer: ElementRef;
scrollToBottom(): void {
try {
this.myScrollContainer.nativeElement.scrollTop = this.myScrollContainer.nativeElement.scrollHeight;
} catch(err) {
}
}
onError() {
// Call scroll to bottom when you want to show error at bottom.
this.scrollToBottom();
}
}
于 2019-06-12T04:40:31.900 回答