我有服務和錯誤處理服務,當我試圖調用對話框代碼,它會給出錯誤。打開/關閉MdDialog裏面的angular2服務
import { MdDialog, MdDialogRef } from '@angular/material';
import { HeaderDialog } from '../dialog-boxes.component';
export class MyService {
dialogRef: MdDialogRef<any>;
constructor(private dialog: MdDialog) {}
this.dialogRef = this.dialog.open(HeaderDialog, {
height: 'auto',
width: 'auto',
});
this.dialogRef.componentInstance.message = 'Hello';
this.dialogRef.afterClosed().subscribe(result => {
if (result) {}
this.dialogRef = null;
});
}
Unhandled Promise rejection: Error: Invalid providers for "HeaderDialog" - only instances of Provider and Type are allowed, got: [EConfig, Constants, ?undefined?, ...]
只有提供者的實例被允許,但你有一個非提供者實例。 –
那麼如何在服務中實現mdDialog?感謝您的回覆。 –
沒有任何適用的方法來做到這一點。 –