最简单的方法是定义生成一个模式的内容页:
ionic g ModalPage
然后你如果命令创建这个文件打开模式,content.module.ts,你必须改变
imports: [
IonicModule.forChild(ModalPage),
],
TO:
imports: [
IonicModule.forRoot(ModalPage),
],
然后你要添加的模态组织一些HTML代码:
<ion-header>
<ion-toolbar>
<ion-title>
GO OUT
</ion-title>
<ion-buttons start>
<button ion-button (click)="dismiss()">
<span ion-text color="primary" showWhen="ios">Cancel</span>
<ion-icon name="md-close" showWhen="android,windows"></ion-icon>
</button>
</ion-buttons>
</ion-toolbar>
</ion-header>
<ion-content>
<p> This is a modal test!!!! </p>
</ion-content>
然后,你必须在声明和应用程序模块的entryComponents进口。
import { ModalPage } from '../pages/modal-page/modal-page';
@NgModule({
declarations: [
MyApp,
HomePage,
Main,
ModalPage
],
imports: [
BrowserModule,
IonicModule.forRoot(MyApp),
HttpModule
],
bootstrap: [IonicApp],
entryComponents: [
MyApp,
HomePage,
ModalPage
],
providers: [
StatusBar,
SplashScreen,
Device,
{provide: ErrorHandler, useClass: IonicErrorHandler}
]
})
然后在页面中您想要执行的模式,你必须添加一个函数到你想用来发射它的元素。
<div full large class="button-el btn-goOut" (tap)="openModal()">
在您要使用的模式的页面,你必须输入:
import { ModalPage } from '../modal-page/modal-page'
重要说明:此元素不应该在构造函数中,调用模式,你只需要做这样的:
openModal(){
let modal = this.modalCtrl.create(ModalPage);
modal.present();
}
尽量避免来自文档的示例代码。总是尝试查看[demo source]中的示例(https://github.com/driftyco/ionic-preview-app/tree/master/src/pages/modals/basic)或[ionic-conference-app](https :// github上。com/driftyco/ionic-conference-app) 因为他们的文档每天都在变化。 – Math10