core.js:4197 ERROR TypeError: Cannot call a class as a function
core.js:4197 ERROR TypeError: Cannot call a class as a function
在为 Angular 应用程序提供服务时,在 Angular v10
中出现以下控制台错误
core.js:4197 ERROR TypeError: Cannot call a class as a function
at _classCallCheck (classCallCheck.js:3)
at new Button (button.js:36)
at ButtonComponent.<anonymous> (createSuper.js:12)
at new ButtonComponent (button.component.ts:30)
at NodeInjectorFactory.ButtonComponent_Factory [as factory] (button.component.ts:57)
at getNodeInjectable (core.js:4029)
at instantiateAllDirectives (core.js:8092)
at createDirectivesInstances (core.js:7474)
at ɵɵelementStart (core.js:14001)
at SBController_Template (template.html:114)
演示:https://github.com/kumaresan-subramani/AngularSampleIssue
重现步骤:
- npm i
- npm 运行 开始
来自 angular 团队的回答 - https://github.com/angular/angular-cli/issues/18125#issuecomment-672069800
我确实看过你的回购协议。看起来你的 ES target
在你的 tsconfig.base.json
文件中被设置为 es5
,它不支持 class。我认为你必须至少从 es6
(es2015
) 开始设置它,然后它应该可以工作:
{
"compilerOptions": {
"target": "es2015",
}
}
在为 Angular 应用程序提供服务时,在 Angular v10
中出现以下控制台错误core.js:4197 ERROR TypeError: Cannot call a class as a function at _classCallCheck (classCallCheck.js:3) at new Button (button.js:36) at ButtonComponent.<anonymous> (createSuper.js:12) at new ButtonComponent (button.component.ts:30) at NodeInjectorFactory.ButtonComponent_Factory [as factory] (button.component.ts:57) at getNodeInjectable (core.js:4029) at instantiateAllDirectives (core.js:8092) at createDirectivesInstances (core.js:7474) at ɵɵelementStart (core.js:14001) at SBController_Template (template.html:114)
演示:https://github.com/kumaresan-subramani/AngularSampleIssue
重现步骤:
- npm i
- npm 运行 开始
来自 angular 团队的回答 - https://github.com/angular/angular-cli/issues/18125#issuecomment-672069800
我确实看过你的回购协议。看起来你的 ES target
在你的 tsconfig.base.json
文件中被设置为 es5
,它不支持 class。我认为你必须至少从 es6
(es2015
) 开始设置它,然后它应该可以工作:
{
"compilerOptions": {
"target": "es2015",
}
}