无法解析模态的所有参数:(?,?,?)

时间:2016-07-23 10:42:46

标签: angular typescript ionic-framework ionic2 ionic3

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 ) {}
}

enter image description here

1 个答案:

答案 0 :(得分:3)

就像@Pace评论一样,您可以查看Ionic2 docs,了解如何创建 a 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'));
 }

}