首页 > 解决方案 > 'NgElementConstructor 类型的参数' 不可分配给“CustomElementConstructor”类型的参数

问题描述

在使用 Angular9 创建 Angular 元素时,我在 VSCode( 1.44.0-insider ) 中收到了一个奇怪的警告:

export class AppModule { 
  constructor(private injector: Injector) {
    const helloElement = createCustomElement(HelloComponent, {injector});
    customElements.define('my-hello', helloElement);
  }
  ngDoBootstrap() {}
}

type ofhelloElement不被接受,并带有来自 typescript 的错误消息:

“NgElementConstructor”类型的参数不可分配给“CustomElementConstructor”类型的参数

标签: angularvisual-studio-codeangular-elements

解决方案


似乎它将在下一个版本中修复:https ://github.com/angular/angular/pull/35864

您已经可以通过更新到下一个版本 (9.1.0-next.4) 为您的项目测试它。

ng update @angular/core --next 

推荐阅读