【问题标题】:StaticInjectorError when using ngx-color-picker inside of MatDialog在 MatDialog 中使用 ngx-color-picker 时出现 StaticInjectorError
【发布时间】:2018-07-24 14:03:51
【问题描述】:

我有一个使用 ngx-color-picker 指令的颜色选择器组件。该组件位于模块的entryComponents 中,并被 MatDialog 像这样使用。

openDialog() { this.dialog.open(EntryComponent, { width: '600px', autoFocus: false }, ); }

当我尝试在颜色选择器组件中使用 ngx-color-picker 的某些功能时,它会抛出 StaticInjectorError

当我使用没有对话框的组件时,只是在一个不在模块的entryComponent 中的简单组件中 - 一切正常。

要重现此问题,请查看此 Stackblitz 项目 https://stackblitz.com/edit/angular-jxkwq2

  1. Open dialog 按钮
  2. 点击黑色矩形
  3. 检查控制台

为什么会发生,我该如何解决?

【问题讨论】:

    标签: angular


    【解决方案1】:

    AppComponent中提供MatDialog

    @Component({
      selector: 'my-app',
      templateUrl: './app.component.html',
      styleUrls: [ './app.component.css' ],
      providers : [MatDialog]
    })
    

    分叉Demo

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2022-12-16
      • 1970-01-01
      • 2020-09-29
      • 1970-01-01
      • 1970-01-01
      • 2016-04-11
      相关资源
      最近更新 更多