[英]Open Angular Bootstrap modal from component
I'm trying to set up a simple modal using angular bootstrap.我正在尝试使用 angular bootstrap 设置一个简单的模态。 But I'm running to this error :
但我遇到了这个错误:
"ERROR Error: No component factory found for ModalContentComponent. Did you add it to @NgModule.entryComponents?
at noComponentFactoryError"
I've imported the module but still unable to get this working.我已经导入了模块,但仍然无法正常工作。 I've started with the documentation HERE and also looked at this StackOverflow question HERE .
我已经开始与文档的位置,也看了这个StackOverflow的问题这里。
Here is my app.module :这是我的 app.module :
import { FormPoster } from './services/form-poster.service';
import { DatepickerModule } from 'ngx-bootstrap/datepicker';
import { ButtonsModule } from 'ngx-bootstrap/buttons';
import { RatingModule } from 'ngx-bootstrap/rating';
import { AddGameComponent } from './add-game/add-game.component';
import { ModalModule } from 'ngx-bootstrap';
@NgModule({
declarations: [
AppComponent,
EmployeeComponent,
EmployeeTitlePipe,
EmployeeListComponent,
EmployeeCountComponent,
HomeComponentComponent,
PageNotFoundComponent,
AddEmployeeComponent,
AddGameComponent,
],
imports: [
BrowserModule,
BrowserAnimationsModule,
FormsModule,
HttpModule,
ButtonsModule.forRoot(),
RatingModule.forRoot(),
ModalModule.forRoot(),
DatepickerModule.forRoot(),
RouterModule.forRoot(appRoutes)
],
providers: [EmployeeService, FormPoster],
bootstrap: [AppComponent]
})
export class AppModule { }
Add ModalContentComponent
inside entryComponent
in your module file.添加
ModalContentComponent
内entryComponent
在你的模块文件。
Like following :像下面这样:
entryComponents: [
ModalContentComponent
]
You should add your component to @NgModule and entryComponents您应该将您的组件添加到@NgModule和entryComponents
Step 1 : Import the component into the app.module.ts步骤 1:将组件导入 app.module.ts
import { CatalogDetailsComponent, ModalContentComponent } from './catalog-details/catalog-details.component'
Step 2 : Add imported module to @NgModule第 2 步:将导入的模块添加到@NgModule
@NgModule({
declarations: [
AppComponent,
ModalContentComponent
],
Step 3 : Add entryComponents below @NgModule if it is not there and add imported component there also第3步:添加entryComponents下面@NgModule如果它不存在,并添加进口组合也有
entryComponents: [
ModalContentComponent
],
将组件作为entryComponents
AND 在declarations
添加到模块中。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.