我想显示一个自定义对话框,但我收到此错误:
HeaderMenuComponent.html:41错误错误:找不到RegisterFormComponent的组件工厂 . 你有没有把它添加到@ NgModule.entryComponents? atComponentComponentFactoryResolver.webpackJsonp中的noComponentFactoryError(core.es5.js:3202),PortalHostDirective的CodegenComponentFactoryResolver.webpackJsonp ... / .. / .. / core / @ angular / core.es5.js.CodegenComponentFactoryResolver.resolveComponentFactory(core.es5.js:3267) MdDialogContainer.webpackJsonp ... / .. / .. / material中的.webpackJsonp ... / .. / .. / cdk/@angular/cdk.es5.js.PortalHostDirective.attachComponentPortal(cdk.es5.js:2706) /@angular/material.es5.js.MdDialogContainer.attachComponentPortal(material.es5.js:17625)at MdDialog.webpackJsonp ... / .. / .. / material / @angular / material.es5.js.MdDialog._attachDialogContent (material.es5.js:17901)位于HeaderMenuComponent.webpackJsonp的MdDialog.webpackJsonp ... / .. / .. / material/@angular/material.es5.js.MdDialog.open(material.es5.js:17813) Object.eval中的... / .. / .. / .. / .. / src / app / header-menu / header-menu.component.ts.HeaderMenuComponent.showRegister(header-menu.component.ts:64) [as handleEvent](HeaderMenuComponent.html:41)at handleEvent(core.es5.js:11997)at callWithDebugContext(core.es5.js:13458) )
我已经尝试用这里提到的解决方案来解决它:Angular2 material dialog has issues - Did you add it to @NgModule.entryComponents? .
但它对我不起作用 .
这是我的代码:app.module.ts
import { BrowserModule } from '@angular/platform-browser';
import { BrowserAnimationsModule } from '@angular/platform-browser/animations';
import { NgModule } from '@angular/core';
import { FormsModule } from '@angular/forms';
import { CollapseModule } from 'ngx-bootstrap/collapse';
import {AccordionModule} from 'ngx-bootstrap/accordion';
import {TabsModule} from 'ngx-bootstrap/tabs';
import {AlertModule} from 'ngx-bootstrap/alert';
import { ModalModule } from 'ngx-bootstrap/modal';
import { Angular2FontawesomeModule } from 'angular2-fontawesome/angular2-fontawesome';
import { HttpModule } from '@angular/http';
import { CoolStorageModule } from 'angular2-cool-storage';
import { SimpleNotificationsModule } from 'angular2-notifications';
import {JasperoAlertsModule} from '@jaspero/ng2-alerts'
import {TreeModule} from 'angular-tree-component';
import {hammerjs} from 'hammerjs';
import { RouterModule, Routes } from '@angular/router';
import {MdDialogModule} from '@angular/material';
import { MaterialModule } from '@angular/material';
import { AppComponent } from './app.component';
import { HeaderMenuComponent } from './header-menu/header-menu.component';
import { LoginFormComponent } from './login-form/login-form.component';
import { CatTreeviewComponent } from './cat-treeview/cat-treeview.component';
import { UserService } from './user.service';
import {CategorieService} from './categorie.service';
import {ArticleService} from './article.service';
import { FooterComponent } from './footer/footer.component';
import { LayoutComponent } from './layout/layout.component';
import { CategorieComponent } from './categorie/categorie.component';
import { ArticlecontainerComponent } from './articlecontainer/articlecontainer.component';
import { ArticleComponent } from './article/article.component';
import { RegisterFormComponent } from './register-form/register-form.component';
@NgModule({
declarations: [
AppComponent,
HeaderMenuComponent,
LoginFormComponent,
CatTreeviewComponent,
FooterComponent,
LayoutComponent,
CategorieComponent,
ArticlecontainerComponent,
ArticleComponent,
RegisterFormComponent
],
entryComponents: [
RegisterFormComponent
],
imports: [
BrowserModule,
CollapseModule.forRoot(),
AccordionModule.forRoot(),
ModalModule.forRoot(),
TabsModule.forRoot(),
AlertModule.forRoot(),
FormsModule,
Angular2FontawesomeModule, HttpModule,
CoolStorageModule,
BrowserAnimationsModule,
SimpleNotificationsModule.forRoot(),
TreeModule,
MaterialModule,
JasperoAlertsModule,
MdDialogModule,
RouterModule.forRoot([
{
path:'index',
component:HeaderMenuComponent
}
])
],
providers: [UserService,CategorieService,ArticleService],
bootstrap: [AppComponent]
})
export class AppModule {
}
这是我的 Headers 组件,我想调用我的寄存器组件:
import { Component, OnInit,Input,Output,EventEmitter } from '@angular/core';
import {CoolLocalStorage} from 'angular2-cool-storage';
import { NotificationsService } from 'angular2-notifications';
import {MdDialog} from '@angular/material';
import { RegisterFormComponent } from '../register-form/register-form.component';
@Component({
selector: 'app-header-menu',
templateUrl: './header-menu.component.html',
styleUrls: ['./header-menu.component.css']
})
export class HeaderMenuComponent implements OnInit {
@Input() currentUser:any;
@Output() onSuccess = new EventEmitter<string>();
public localStorage:CoolLocalStorage;
public isCollapsed:boolean = false;
public isDropdownCollapsed:boolean = true;
toast:any;
public options = {
position: ["bottom,right"],
timeOut: 5000,
lastOnBottom: true,
clickToClose:true
}
public collapsed(event:any):void{
console.log(event);
}
public expanded(event:any):void{
console.log(event);
}
closeModal() {}
logout()
{
this.localStorage.removeItem('wikiCurrentUser');
window.location.reload();
}
constructor(localStorage:CoolLocalStorage,private _service: NotificationsService,public dialog:MdDialog) {
this.localStorage = localStorage;
}
ngOnInit() {
this.currentUser = this.localStorage.getObject('wikiCurrentUser');
}
showSuccess(mess:string)
{
// if(this.toast != null)
// this._service.remove(this.toast.id);
// this.toast = this._service.info("Enregistrement terminé!",mess);
// setTimeout(()=>{
// window.location.reload();
// },5000);
this.onSuccess.emit(mess);
}
showRegister()
{
this.dialog.open(RegisterFormComponent);
}
}
关于我做错了什么的任何想法?感谢你们!
1 回答
我今天遇到了同样的问题,这是我解决问题的步骤:
在此处查看完整源代码并运行应用程序:Calendar . (提交编号9中添加的模态窗口)