简体   繁体   English

Class 正在使用 Angular 功能,但未在 angular 14 中进行修饰

[英]Class is using Angular features but is not decorated in angular 14

I have updated my angular app from 13 to 14. After update i am getting below error after opening component class in vs code.我已将我的 angular 应用程序从 13 更新到 14。更新后,我在 vs 代码中打开组件 class 后出现以下错误。

Class is using Angular features but is not decorated. Class 正在使用 Angular 功能但未修饰。 Please add an explicit Angular decorator请添加一个明确的 Angular 装饰器

I have checked this question我检查过这个问题

But i have not using any ineritance in the app.但我没有在应用程序中使用任何惯性。

在此处输入图像描述

But the application run perfectly.但是应用程序运行完美。 How to remove that error?如何消除该错误?

ts.confing ts.confing

/* To learn more about this file see: https://angular.io/config/tsconfig . /* 要了解有关此文件的更多信息,请参阅: https://angular.io/config/tsconfig */ */

{
  "compileOnSave": false,
  "compilerOptions": {
    
    "baseUrl": "./",
    "outDir": "./dist/out-tsc",
    "forceConsistentCasingInFileNames": false,
    "strict": false,
    "allowSyntheticDefaultImports":true, 
    "noImplicitOverride": true,
    "noPropertyAccessFromIndexSignature": true,
    "noImplicitReturns": true,
    "noFallthroughCasesInSwitch": true,
    "sourceMap": true,
    "declaration": true,
    "downlevelIteration": true,
    "experimentalDecorators": true,
    "moduleResolution": "node",
    "importHelpers": true,
    "target": "es2022",
    "module": "es2022",
    "lib": [
      "es2022",
      "dom"
    ],
    "paths": {
      "stream": [ "./node_modules/stream-browserify" ]
    },
  },
  "angularCompilerOptions": {
    "enableI18nLegacyMessageIdFormat": false,
    "strictInjectionParameters": true,
    "strictInputAccessModifiers": true,
    "strictTemplates": false,
  }
}

Validation component验证组件

import { Component, Input } from '@angular/core';
import { AbstractControl } from '@angular/forms';
import { ValidationService } from 'src/app/core/services/validation.service';

@Component({
  selector: 'app-validation-message',
  template: '<div *ngIf="errorMessage !== null" style="width:50%;margin-top:.25rem;font-size:80%;color:#dc3545">{{errorMessage}}</div>'
})

export class ValidationMessageComponent {
  @Input() control: AbstractControl;

  constructor() {
  }

  get errorMessage() {
    if (this.control.errors) {
    
      for (let propertyName in this.control.errors) {
        if (this.control.errors.hasOwnProperty(propertyName) && this.control.touched) {
          return ValidationService.getValidatorErrorMessage(propertyName, this.control.errors[propertyName]);
        }
      }
    }
    return null;
  }
}

Had the same issue.有同样的问题。 Typescript downgrade from 4.7.4 to 4.7.2 resolved the problem. Typescript 从 4.7.4 降级到 4.7.2 解决了这个问题。

npm i typescript@4.7.2

it is due to Angular Language Service extension, it does not support Typescript 4.8 yet, see related issue here: https://github.com/angular/vscode-ng-language-service/issues/1746这是由于 Angular 语言服务扩展,它不支持 Typescript 4.8 ,请在此处查看相关问题: https://github.com/issue-angular/17service46

I had the same problem, i resolve it by downgrading typescript dependencies:我遇到了同样的问题,我通过降级 typescript 依赖项来解决它:

"@typescript-eslint/eslint-plugin": "5.29.0",
"@typescript-eslint/parser": "5.29.0",
"typescript": "4.7.2"

now the error is gone and all is working perfectly现在错误消失了,一切正常

Same issue with Angular 15. This time upgrading typescript from 4.8.2 to 4.8.4 solved the problem.与 Angular 15 相同的问题。这次将 typescript 从 4.8.2 升级到 4.8.4 解决了问题。

initially i had typescript 4.8.4 when hitting this problem.最初我遇到这个问题时有 typescript 4.8.4。 after i read through here, I downgraded to 4.7.2, didn't work;看完这里后,我降级到 4.7.2,没用; then I went back to 4.8.4, interestingly it worked.然后我回到 4.8.4,有趣的是它起作用了。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 Class 正在使用 Angular 功能但未使用 Typescript 4.8.2 进行装饰 - Class is using Angular features but is not decorated with Typescript 4.8.2 Angular 11 '错误 NG2007:Class 正在使用 Angular 功能但未修饰。 但是 class 是装饰的 - Angular 11 'error NG2007: Class is using Angular features but is not decorated.' But the class is Decorated 问:Angular 组件损坏 - “类正在使用 Angular 功能但未装饰。请添加显式 Angular 装饰器” - Q: Angular components broken - "Class is using Angular features but is not decorated. Please add an explicit Angular decorator" Angular 15: Class 正在使用 Angular 功能但未修饰。 请添加明确的 Angular 装饰器。(-992007) - Angular 15 : Class is using Angular features but is not decorated. Please add an explicit Angular decorator.(-992007) 类使用 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 库基础 class 没有任何装饰器但使用 Angular 功能 - Angular Library base class without any decorator but using Angular features “......用可注射装饰” - Angular2 - "...decorated with Injectable" - Angular2 使用带有 SCSS 的 Angular 14 中的 Bootstrap 5 - Using Bootstrap 5 in Angular 14 with SCSS Angular2中的装饰/计算数组 - Decorated/Computed arrays in Angular2
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM