簡體   English   中英

Angular NullInjectorError

[英]Angular NullInjectorError

我正在嘗試將MatDialogRef添加到我的代碼中。 我按照不同答案中提到的步驟進行操作。 例如,我將@angular/material導入更改為@angular/material/dialog ,添加了@Inject(MAT_DIALOG_DATA)等。然而,當頁面打開時我仍然收到此錯誤。 我還應該做什么?

在此處輸入圖像描述

代碼:

 import { MatDialog, MatDialogRef, MAT_DIALOG_DATA} from '@angular/material/dialog';
    @Component({
      selector: 'sticker-preview',
      templateUrl: './sticker-preview.component.html',
      styleUrls: ['./sticker-preview.component.scss']
    })
    export class StickerPreviewComponent implements OnInit {
      EditIndex: number;
      private _stickerData: IStickerData;
      confirmDialogRef: MatDialogRef<FuseConfirmDialogComponent>;

      constructor(
        private _router: Router, 
        private _fuseSidebarService: FuseSidebarService, 
        private _productionService: ProductionService,
        private _dialog: MatDialog,
        private _messages: Messages,
        private _dialogRef: MatDialogRef<StickerPreviewComponent>,
        @Inject(MAT_DIALOG_DATA) private _data: IStickerData,
        ) {
          this._stickerData = _data;
    }
save(){
    this.confirmDialogRef.componentInstance.confirmMessage =
    "Label will be changed. Are you sure?";

this.confirmDialogRef.afterClosed().subscribe((result) => {
    if (result) {
        this._productionService
            .saveStickerData(this._stickerData)
            .subscribe((response: IStickerData) => {
                this._stickerData = response;
                this._messages.Show(
                    "Sticker has updated",
                    "SUCCESS",
                    3
                );
                this._dialogRef.close(response);
            });
    }
});
}
}

我正在嘗試將MatDialogRef添加到我的代碼中。 我按照不同答案中提到的步驟進行操作。 例如,我將@angular/material導入更改為@angular/material/dialog ,添加了@Inject(MAT_DIALOG_DATA)等。然而,當頁面打開時我仍然收到此錯誤。 我還應該做什么?

在此處輸入圖像描述

代碼:

 import { MatDialog, MatDialogRef, MAT_DIALOG_DATA} from '@angular/material/dialog';
    @Component({
      selector: 'sticker-preview',
      templateUrl: './sticker-preview.component.html',
      styleUrls: ['./sticker-preview.component.scss']
    })
    export class StickerPreviewComponent implements OnInit {
      EditIndex: number;
      private _stickerData: IStickerData;
      confirmDialogRef: MatDialogRef<FuseConfirmDialogComponent>;

      constructor(
        private _router: Router, 
        private _fuseSidebarService: FuseSidebarService, 
        private _productionService: ProductionService,
        private _dialog: MatDialog,
        private _messages: Messages,
        private _dialogRef: MatDialogRef<StickerPreviewComponent>,
        @Inject(MAT_DIALOG_DATA) private _data: IStickerData,
        ) {
          this._stickerData = _data;
    }
save(){
    this.confirmDialogRef.componentInstance.confirmMessage =
    "Label will be changed. Are you sure?";

this.confirmDialogRef.afterClosed().subscribe((result) => {
    if (result) {
        this._productionService
            .saveStickerData(this._stickerData)
            .subscribe((response: IStickerData) => {
                this._stickerData = response;
                this._messages.Show(
                    "Sticker has updated",
                    "SUCCESS",
                    3
                );
                this._dialogRef.close(response);
            });
    }
});
}
}

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM