簡體   English   中英

StaticInjectorError(AppModule)[AppComponent -> DialogComponent]

[英]StaticInjectorError(AppModule)[AppComponent -> DialogComponent]

我正在嘗試使用 Kendo 庫創建一個可重用的對話框,但是這樣做時我總是得到以下錯誤。

錯誤:StaticInjectorError(AppModule)[AppComponent -> DialogComponent]: StaticInjectorError(Platform: core)[AppComponent -> DialogComponent]: NullInjectorError: No provider for DialogComponent!

這是我的組件文件

import { Component, OnInit } from '@angular/core';
import {  DialogService,
          DialogRef,
          DialogCloseResult } from '@progress/kendo-angular-dialog';

@Component({
  selector: 'app-dialog',
  templateUrl: './dialog.component.html',
  styleUrls: ['./dialog.component.css']
})
export class DialogComponent {

  constructor( private dialogService: DialogService ) {}

  public open() {
    const dialog = this.dialogService.open({
      title: 'Please confirm',
      content: 'Are you sure?',
      actions: [
        { text: 'No' },
        { text: 'Yes', primary: true }
      ]
    });

    dialog.result.subscribe((result) => {
      if (result instanceof DialogCloseResult) {
        console.log('close');
      } else {
        console.log('action', result);
      }
    });
}
}

我嘗試了幾件事,但沒有運氣克服這個錯誤。

Stackblitz 代碼

添加import { DialogService } from '@progress/kendo-angular-dialog'; 在你的app.module.ts

DialogService中的 providers 數組在同一個文件中。

並在DialogComponent的導出數組中添加app.module.ts

暫無
暫無

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

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