简体   繁体   English

Angular 15: Class 正在使用 Angular 功能但未修饰。 请添加明确的 Angular 装饰器。(-992007)

[英]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.

相关问题 问:Angular 组件损坏 - “类正在使用 Angular 功能但未装饰。请添加显式 Angular 装饰器” - Q: Angular components broken - "Class is using Angular features but is not decorated. Please add an explicit Angular decorator" 类使用 Angular 特性但没有修饰。 请添加一个显式的 Angular 装饰器 - Class is using Angular features but is not decorated. Please add an explicit Angular decorator 如何在不出错的情况下实现 OnInit:Class 正在使用 Angular 功能但未进行装饰。 请添加显式 Angular 装饰器 - How do I implement OnInit without getting error: Class is using Angular features but is not decorated. Please add an explicit Angular decorator Angular 11 '错误 NG2007:Class 正在使用 Angular 功能但未修饰。 但是 class 是装饰的 - Angular 11 'error NG2007: Class is using Angular features but is not decorated.' But the class is Decorated Class 正在使用 Angular 功能,但未在 angular 14 中进行修饰 - Class is using Angular features but is not decorated in angular 14 Class 正在使用 Angular 功能但未使用 Typescript 4.8.2 进行装饰 - Class is using Angular features but is not decorated with Typescript 4.8.2 Angular 库基础 class 没有任何装饰器但使用 Angular 功能 - Angular Library base class without any decorator but using Angular features 如何使用 typescript 中的装饰器向 class 添加和声明新属性(角度) - How to add and declare new property to class using decorator in typescript (angular) Angular 15 - 考虑使用 @Inject 装饰器指定注入令牌 - Angular 15 - Consider using the @Inject decorator to specify an injection token 装饰器何时以及如何应用于@angular包中的装饰类 - When and how s decorator applied to the decorated classes from the @angular packages
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM