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 ) {}
}
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试):
问题:
回答1:
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'));
}
}