如何在打開帶有 Angular 和 Angular 材質的組件之前顯示對話框?
我有 2 個組件,第一個組件包含一個按鈕 onclick 路由到第二個組件。我想在打開第二個組件時顯示一個彈出視窗或對話框。
我怎樣才能做到這一點 !
我使用 Angular 8 和 Angular 材料。
uj5u.com熱心網友回復:
沒關系,我找到了解決方案
只是我試過了,效果很好
在我添加的第二個組件中:
import { MatDialog } from '@angular/material';
import { DialogComponent } from '../../dialog-video/dialog.component';
//... other lines
constructor(public dialog: MatDialog) {}
ngAfterViewInit() {
this.dialog.open(DialogComponent);
}
uj5u.com熱心網友回復:
import { BsModalRef, BsModalService } from 'ngx-bootstrap/modal';
import { Router } from '@angular/router';
constructor(private modalService: BsModalService,
private router: Router) { }
clickToShowComponent() {
this.bsModalRef = this.modalService.show(SecondComponent);
this.secondComponentSubscription = this.modalService.onHide.subscribe((routeToSecondComponent: any) => {
if(routeToSecondComponent) {
this.router.navigate(['/secondComponentRoute']);
}
this.secondComponentSubscription.unsubscribe();
});
}
轉載請註明出處,本文鏈接:https://www.uj5u.com/caozuo/332674.html
上一篇:使用按鈕單擊更改兩個組件的顏色
