我正在构建一个Ionic2应用程序,并尝试从(它将成为一个表单)组件打开一个模态。
模态本身:
import { NavController } from 'ionic-angular';
import { FormBuilder, FormGroup } from '@angular/forms';
export class AddCigarFormBuilder {
myForm: FormGroup;
private myData: any;
constructor(private navCtrl: NavController, private builder: FormBuilder) {
this.myForm = builder.group({
'subject': '',
'message': ''
})
}
onSubmit(formData) {
console.log('Form data is ', formData);
this.myData = formData;
}
}
它是HTML:
<form [formGroup]="myForm" (ngSubmit)="onSubmit(myForm.value)">
<ion-item>
<ion-label floating>Subject</ion-label>
<ion-input type="text" formControlName="subject" name="subject"></ion-input>
</ion-item>
<ion-item>
<ion-label floating>Message</ion-label>
<ion-textarea type="text" formControlName="message" name="message"></ion-textarea>
</ion-item>
<button block>
<ion-icon name="add"></ion-icon>Add</button>
</form>
我试图打开它的组件:
import { AddCigarFormBuilder } from '../form_add_cigar_to_list/add_cigar_form.component';
@Component({
selector: 'cigar_list',
templateUrl: 'cigar_list.html'
})
export class CigarList {
constructor(public nav : NavController, public modalCtrl: ModalController) {
this.nav = nav;
}
presentAddCigarModal() {
let addCigarModal = this.modalCtrl.create(AddCigarFormBuilder,
{
}
);
addCigarModal.present();
}
}
它是HTML:
<ion-fab right top>
<button ion-fab color="secondary" (click)="presentAddCigarModal()">
<ion-icon name="md-add"></ion-icon>
</button>
</ion-fab>
在我的app.module.ts中:
import { CigarList } from '../pages/cigar_list/cigar_list.component';
import { AddCigarFormBuilder } from '../pages/form_add_cigar_to_list/add_cigar_form.component';
@NgModule({
imports: [
IonicModule.forRoot(MyApp),
TranslateModule.forRoot({
provide: TranslateLoader,
useFactory: (createTranslateLoader),
deps: [Http]
}),
IonicImageViewerModule
],
declarations: [
MyApp,
CigarList,
AddCigarFormBuilder,
],
bootstrap: [IonicApp],
entryComponents: [
MyApp,
CigarList,
AddCigarFormBuilder,
],
providers: [{provide: ErrorHandler, useClass: IonicErrorHandler, }]
})
export class AppModule {}
我没有更改app.component.ts中的任何内容。
这给了我以下错误:
Unexpected value 'AddCigarFormBuilder' declared by the module 'AppModule'
我在这里做错了什么?如果我从模块中删除AddCigarFormBuilder,则应用程序启动但单击它抛出的按钮:
ModalCmp ionViewPreLoad error: No component factory found for AddCigarFormBuilder
错误。