我有一个弹出框,我希望我的应用程序根据所选项目的不同而有所不同。为了实现这一目标,我遵循了那个离子文档。
Error: Uncaught (in promise): Error: No provider for ViewController!
因此,如果我将视图控制器添加到app.module.ts
,则会收到以下错误:
Uncaught Error: Can't resolve all parameters for ViewController: (?, ?, ?)
问:如何正确导入视图控制器?
弹出框组件:
import { Component } from '@angular/core';
import { ViewController } from 'ionic-angular';
@Component({
selector: 'popover',
templateUrl: 'popover.html'
})
export class PopoverComponent {
popoverItemList = [{name: 'Event erstellen'}, {name: 'Event Übersicht'}];
selectedTitle: string;
constructor(private viewCtrl: ViewController) {
this.selectedTitle = "";
}
setSelectedTitle(selectedItem) {
this.selectedTitle = selectedItem;
this.viewCtrl.dismiss(this.selectedTitle);
}
}
我这样称呼弹出框:
presentPopover(ev) {
let popover = this.popoverCtrl.create(PopoverComponent, {
});
popover.present({
ev: ev
});
popover.onDidDismiss((popoverData) => {
if(popoverData === 'Event erstellen') {
this.navCtrl.push(CreateEventPage, {
});
} else if(popoverData === 'Event Übersicht') {
this.navCtrl.push(EventlistPage, {
});
}
})
从 '@angular/core' 导入 { ViewChild };从"ionic-angular"导入 { 视图控制器 };
不是在构造中声明,而是在@ViewChild(视图控制器)视图中声明:视图控制器;
import { ModalController } from '@ionic/angular';
constructor(private viewCtrl : ModalController) { }
this.viewCtrl.dismiss();
import { Component } from '@angular/core';
import { ViewController } from 'ionic-angular';
@Component({
selector: 'popover',
templateUrl: 'popover.html',
providers : [ViewController] //add this line
})
export class PopoverComponent {
popoverItemList = [{name: 'Event erstellen'}, {name: 'Event Übersicht'}];
selectedTitle: string;
constructor(private viewCtrl: ViewController) {
this.selectedTitle = "";
}
setSelectedTitle(selectedItem) {
this.selectedTitle = selectedItem;
this.viewCtrl.dismiss(this.selectedTitle);
}
}