gpt4 book ai didi

angular - 在 Ionic 中实现弹出 Controller

转载 作者:行者123 更新时间:2023-12-01 22:04:29 25 4
gpt4 key购买 nike

简要说明:尝试在home.html页面上实现弹出 Controller 。尝试按照文档进行操作,但仍然无法完成。

我在 home.ts 旁边创建了 popover.ts 页面,但是当我尝试导入 home.ts 时,它说找不到模块“popover”

我做错了什么?

home.ts

import { PopoverController } from 'ionic-angular';
import { PopoverPage } from 'popover';

@Component({})
class MyPage {
constructor(public popoverCtrl: PopoverController) {}

presentPopover(myEvent) {
let popover = this.popoverCtrl.create(PopoverPage);
popover.present({
ev: myEvent
});
}
}

popover.ts

import { Component } from '@angular/core';
import { ViewController } from 'ionic-angular';


@Component({
template: `
<ion-list>
<ion-list-header>Ionic</ion-list-header>
<button ion-item (click)="close()">Learn Ionic</button>
<button ion-item (click)="close()">Documentation</button>
<button ion-item (click)="close()">Showcase</button>
<button ion-item (click)="close()">GitHub Repo</button>
</ion-list>
`
})
class PopoverPage {
constructor(public viewCtrl: ViewController) {}

close() {
this.viewCtrl.dismiss();
}
}

最佳答案

试试这个

home.ts

import { PopoverController } from 'ionic-angular';
import { PopoverPage } from './popover';

@Component({})
export class MyPage {
constructor(public popoverCtrl: PopoverController) {}

presentPopover(myEvent) {
let popover = this.popoverCtrl.create(PopoverPage);
popover.present({
ev: myEvent
});
}
}

popover.ts

import { Component } from '@angular/core';
import { ViewController } from 'ionic-angular';


@Component({
template: `
<ion-list>
<ion-list-header>Ionic</ion-list-header>
<button ion-item (click)="close()">Learn Ionic</button>
<button ion-item (click)="close()">Documentation</button>
<button ion-item (click)="close()">Showcase</button>
<button ion-item (click)="close()">GitHub Repo</button>
</ion-list>
`
})
export class PopoverPage {
constructor(public viewCtrl: ViewController) {}

close() {
this.viewCtrl.dismiss();
}
}

关于angular - 在 Ionic 中实现弹出 Controller ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/48094223/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com