Angular Can';t解析角度依赖注入的所有参数
因此,我围绕Priming的MessageService创建了一个包装器,并将其注入到我的组件中。代码运行正常,消息显示完整,但VSCode用红色下划线标记我的组件类,并表示: 无法解析中ProductListComponent的所有参数 …/read/product-list.component.ts:([object object],[object object], ?,[object object],[object object]).ng 这是我的组件类:Angular Can';t解析角度依赖注入的所有参数,angular,visual-studio-code,primeng,Angular,Visual Studio Code,Primeng,因此,我围绕Priming的MessageService创建了一个包装器,并将其注入到我的组件中。代码运行正常,消息显示完整,但VSCode用红色下划线标记我的组件类,并表示: 无法解析中ProductListComponent的所有参数 …/read/product-list.component.ts:([object object],[object object], ?,[object object],[object object]).ng 这是我的组件类: @Component({ t
@Component({
templateUrl: 'product-list.component.html'
})
export class ProductListComponent {
constructor(
private breadcrumbService: BreadcrumbService,
productService: Productservice,
private messageServiceWrapper: MessageServiceWrapper,
private confirmationService: ConfirmationService,
private translate: TranslateService
) {}
}
这是Angular无法注入的服务:
import { MessageService } from 'primeng';
import { Injectable } from '@angular/core';
@Injectable({ providedIn: 'root' })
export default class MessageServiceWrapper {
constructor(private messageService: MessageService) {
this.clearMessages();
}
showErrorMessage(summary: string, detail: string): void {
this.clearMessages();
this.messageService.add({ key: 'local', severity: 'error', summary, detail });
}
showInfoMessage(summary: string, detail: string): void {
this.clearMessages();
this.messageService.add({ key: 'local', severity: 'info', summary, detail });
}
clearMessages(): void {
this.messageService.clear();
}
showSuccessMessage(summary: string): void {
this.clearMessages();
this.messageService.add({ key: 'local', severity: 'success', summary });
}
}
组件的模块:
@NgModule({
declarations: [
...
ProductListComponent,
...
],
schemas: [NO_ERRORS_SCHEMA],
imports: [
SharedModule,
CommonModule,
MessagesModule,
MessageModule,
CardModule,
InputSwitchModule,
ConfirmDialogModule,
InputTextModule,
DialogModule,
AutoCompleteModule,
ToastModule,
FileUploadModule,
PaginatorModule,
ButtonModule,
TranslateModule,
AppTableModule,
ProductRoutingModule,
],
})
export class ProductModule {}
我尝试在共享模块中声明服务,但也没有任何帮助。尝试从“导出默认类MessageServiceWrapper”叶导出类中删除“default”MessageServiceWrapper@TomaszVizaint这确实奏效了!但是为什么呢?就在今天,我遇到了同样的问题,删除默认值看起来像是一个打开的文件,用于注入,不知道这是为什么,因为AOT编译器不希望以这种方式导出服务,由于它应该创建正确的元数据,因此会丢失作为defaulttry导出的类,请将行
productService:productService
更改为private-productService:productService