English 中文(简体)
裁决人在此无效。 模块构造
原标题:Decorators are not valid here, Angular component constructor

我正试图在安吉斯17使用安热材料建立一个方言部分。

在方言构造中,我无法像正式文件中提供的例子那样使用@Inject decorator。

import { Component, Inject } from  @angular/core ;
import { MatDialog, MatDialogRef } from  @angular/material/dialog ;

@Component({
  selector:  app-reject ,
  standalone: true,
  imports: [MaterialModule],
  templateUrl:  ./reject.component.html ,
  styleUrl:  ./reject.component.scss ,
})
export class RejectComponent {
  constructor(
    @Inject(MAT_DIALOG_DATA) public data: any, //Decorators are not valid here.ts(1206)
    public dialogRef: MatDialogRef<RejectComponent>,
  ) {}

  public editorConfig = EDITOR_CONFIG;

  commentFormControl = new FormControl(  );

  onCancel(): void {
    this.dialogRef.close();
  }
}

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"],
    "paths": {},
    "rootDir": "."
  },
  "angularCompilerOptions": {
    "enableI18nLegacyMessageIdFormat": false,
    "strictInjectionParameters": true,
    "strictInputAccessModifiers": true,
    "strictTemplates": true
  },
  "exclude": ["node_modules", "tmp"]
}

Angular version: 17.0.7 Material version: 17.0.4

问题回答

或者,你可以使用注射功能,这种功能可以解决在建筑注射之外的依赖。

import {inject} from  @angular/core ;
export class RejectComponent {
   public data = inject(MAT_DIALOG_DATA);
   public dialogRef:MatDialogRef<RejectComponent> = inject(RejectComponent)
   ....

}




相关问题
Angular matSort not working on Date column by desc

Trying to sort the material table with date column , date format is MM/DD/YYYY ,h:mm A , order of date is not by latest date and time. Anything which i missed from the below stackblitz code. https:/...

热门标签