1
import { Component, Inject } from '@angular/core';
import { NavController, Modal } from 'ionic-angular';

import { PopupPage } from '../../components/modal/modal.page';

@Component({
  templateUrl: 'build/pages/spot/spot.html',
  providers: [ Modal ]
})
export class SpotComponent {

  constructor(@Inject(Modal) private modal: Modal ) {}
}

在此处输入图像描述

4

1 回答 1

3

就像@Pace 评论的那样,您可以查看Ionic2 文档以了解如何创建Modal.

您不必将它包含在providers数组或constructor您正在做的事情中。相反,您应该使用如下Modal.create(...)方法:

import { Modal, NavController, NavParams } from 'ionic-angular';

@Component(...)
class HomePage {

 constructor(/* ..., */ private nav: NavController) {
   // Your code...
 }

 presentProfileModal() {
   // Create the modal using the layout from the Profile Component
   let profileModal = Modal.create(Profile, { paramId: 12345 });

   // Show the modal
   this.nav.present(profileModal);
 }

}

@Component(...)
class Profile {

 constructor(/* ..., */ private params: NavParams) {
   // Get the parameter by using NavParams
   console.log('paramId', params.get('paramId'));
 }

}
于 2016-07-23T12:18:22.037 回答