[英]Angular 15 : Class is using Angular features but is not decorated. Please add an explicit Angular decorator.(-992007)
I'm using Angular 15. Created a new Angular component as follows我正在使用 Angular 15. 创建了一个新的 Angular 组件如下
import { Component } from '@angular/core';
@Component({
selector: 'app-foo',
templateUrl: './foo.component.html',
styleUrls: ['./foo.component.css']
})
export class FooComponent {
}
When I implement the OnInit
interface,当我实现
OnInit
接口时,
import { Component, OnInit } from '@angular/core';
@Component({
selector: 'app-foo',
templateUrl: './foo.component.html',
styleUrls: ['./foo.component.css']
})
export class FooComponent implements OnInit {
ngOnInit(): void {
}
}
I get following error.我收到以下错误。
Class is using Angular features but is not decorated.
Class 正在使用 Angular 功能但未修饰。 Please add an explicit Angular decorator.(-992007)
请添加明确的 Angular 装饰器。(-992007)
Detailed Configuration of my project.我的项目的详细配置。
package.json package.json
{
"name": "client1",
"version": "0.0.0",
"scripts": {
"ng": "ng",
"start": "ng serve",
"build": "ng build",
"watch": "ng build --watch --configuration development",
"test": "ng test"
},
"private": true,
"dependencies": {
"@angular/animations": "^15.1.0",
"@angular/common": "^15.1.0",
"@angular/compiler": "^15.1.0",
"@angular/core": "^15.1.0",
"@angular/forms": "^15.1.0",
"@angular/platform-browser": "^15.1.0",
"@angular/platform-browser-dynamic": "^15.1.0",
"@angular/router": "^15.1.0",
"rxjs": "~7.8.0",
"tslib": "^2.3.0",
"zone.js": "~0.12.0"
},
"devDependencies": {
"@angular-devkit/build-angular": "^15.1.1",
"@angular/cli": "~15.1.1",
"@angular/compiler-cli": "^15.1.0",
"@types/jasmine": "~4.3.0",
"jasmine-core": "~4.5.0",
"karma": "~6.4.0",
"karma-chrome-launcher": "~3.1.0",
"karma-coverage": "~2.2.0",
"karma-jasmine": "~5.1.0",
"karma-jasmine-html-reporter": "~2.0.0",
"typescript": "~4.9.4"
}
}
tsconfig.json tsconfig.json
{
"compileOnSave": false,
"compilerOptions": {
"baseUrl": "./",
"outDir": "./dist/out-tsc",
"forceConsistentCasingInFileNames": true,
"strict": true,
"noImplicitOverride": true,
"noPropertyAccessFromIndexSignature": true,
"noImplicitReturns": true,
"noFallthroughCasesInSwitch": true,
"sourceMap": true,
"declaration": false,
"downlevelIteration": true,
"experimentalDecorators": true,
"moduleResolution": "node",
"importHelpers": true,
"target": "ES2022",
"module": "ES2022",
"useDefineForClassFields": false,
"lib": [
"ES2022",
"dom"
]
},
"angularCompilerOptions": {
"enableI18nLegacyMessageIdFormat": false,
"strictInjectionParameters": true,
"strictInputAccessModifiers": true,
"strictTemplates": true
}
}
https://github.com/angular/angular/issues/48741 . https://github.com/angular/angular/issues/48741 。
After disabling the VS code extension "Angular Language Service" everything works fine now.禁用 VS 代码扩展“Angular Language Service”后,现在一切正常。
If you are facing the same error even before building or running the application, try disabling VS code extensions related to Angular or JavaScript. Might work.如果您甚至在构建或运行应用程序之前遇到相同的错误,请尝试禁用与 Angular 或 JavaScript 相关的 VS 代码扩展。可能会起作用。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.