我有一个Popover,我希望我的应用根据所选项目的不同而有所不同。 为实现这一目标,我遵循了Ionic Doc。
Error: Uncaught (in promise): Error: No provider for ViewController!
因此,如果我将ViewController添加到app.module.ts
,我会收到以下错误:
Uncaught Error: Can't resolve all parameters for ViewController: (?, ?, ?)
问题:如何正确导入ViewController?
popover组件:
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);
}
}
我这样称呼popover:
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, {
});
}
})
答案 0 :(得分:0)
从'@ angular / core'导入{ViewChild}; 从“ ionic-angular”导入{ViewController};
不是在Construct中声明,而是在@ViewChild(ViewController)视图中声明:ViewController;
答案 1 :(得分:-3)
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);
}
}