gpt4 book ai didi

Angular 8 : ERROR Error: No component factory found

转载 作者:行者123 更新时间:2023-12-04 16:50:31 34 4
gpt4 key购买 nike

我在同一个 ts 文件中创建了两个组件,如下所示。引用来自 https://material.angular.io/components/dialog/examples 的示例代码它使用相同的方法。

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


@Component({
selector: 'app-srapi',
templateUrl: './srapi.component.html',
styleUrls: ['./srapi.component.scss']
})
export class SrapiComponent {

constructor(private dialog: MatDialog) { }

onCreate(): void {
const dialogRef = this.dialog.open(SrapiTFLFormComponent);
}
}

@Component({
selector: 'app-srapi-tfl-form',
templateUrl: './srapi-tfl-form.html'
})
export class SrapiTFLFormComponent{

constructor(public dialogRef: MatDialogRef<SrapiTFLFormComponent>) {}
}

还在 app.module.ts 中声明和进口了这两个
import { SrapiComponent, SrapiTFLFormComponent } from './srapi/srapi.component';

@NgModule({
declarations: [
AppComponent,
LoginComponent,
HeaderComponent,
FooterComponent,
RegisterComponent,
EdcUserFormComponent,
SidebarComponent,
EdcMasterDataComponent,
SrapiComponent,
SrapiTFLFormComponent
],
imports: [
BrowserModule,
.
.

但是在打开对话框时会出错。

ERROR Error: No component factory found for SrapiTFLFormComponent. Did you add it to @NgModule.entryComponents? at noComponentFactoryError (core.js:15705)

最佳答案

在您的 app.module.ts添加以下代码:

import { SrapiComponent, SrapiTFLFormComponent } from './srapi/srapi.component';

@NgModule({
declarations: [
AppComponent,
LoginComponent,
HeaderComponent,
FooterComponent,
RegisterComponent,
EdcUserFormComponent,
SidebarComponent,
EdcMasterDataComponent,
SrapiComponent,
SrapiTFLFormComponent
],
imports: [
BrowserModule,
.
.
],
entryComponents: [
SrapiTFLFormComponent
]

关于 Angular 8 : ERROR Error: No component factory found,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/56390787/

34 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com