选择“ es2015”目标会给指令带来不确定的错误

时间:2019-02-08 11:21:00

标签: angular typescript ecmascript-6

我有一个名为“ ModalHost”的指令,如下所示:

@Directive({
  selector: '[ModalHost]',
  exportAs: 'ModalHost'
})
export class ModalHost {
  constructor(public viewContainerRef: ViewContainerRef, private componentFactoryResolver: ComponentFactoryResolver) { }
......
}

并且我正在其中一个组件中将其用作这样的输入属性:

@Input('modalHost') public modalHost: ModalHost;

当Typescript的编译器定位为'es5'时,一切工作都很好,但是当我将其更改为'es2015'时,会出现错误提示:

Uncaught referenceError: ModalHost is not defined at Module.ModalHost (my-component.component.ts)

这里是“ tsconfig.json”以获取更多信息:

{
  "compileOnSave": true,
  "compilerOptions": {
    "baseUrl": "./",
    "outDir": "./dist/out-tsc",
    "sourceMap": true,
    "moduleResolution": "node",
    "emitDecoratorMetadata": true,
    "experimentalDecorators": true,
    "noImplicitAny": false,
    "target": "es2015",
    "typeRoots": [
      "node_modules/@types"
    ],
    "lib": [
      "es2015",
      "dom"
    ],
  }
}

0 个答案:

没有答案