Can't resolve all parameters for Modal: (?, ?,

2019-08-01 16:31发布

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条回答
何必那么认真
2楼-- · 2019-08-01 16:48

Just like @Pace commented, you can take a look at Ionic2 docs to see how to create a Modal.

You don't have to include it in the providers array or in your constructor like you're doing. Instead you should use the Modal.create(...) method like this:

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'));
 }

}
查看更多
登录 后发表回答