I have followed ionicframework ModalController example (link below)
“https://ionicframework.com/docs/v2/api/components/modal/ModalController/”
import { ModalController, NavParams } from 'ionic-angular';
@Component(...)
class HomePage {
constructor(public modalCtrl: ModalController) {
}
presentProfileModal() {
let profileModal = this.modalCtrl.create(Profile, { userId: 8675309 });
profileModal.present();
}
}
@Component(...)
class Profile {
constructor(params: NavParams) {
console.log('UserId', params.get('userId'));
}
}
I get this error
has anyone else encountered the same error and how did you fix it?
inside the modal page, for the @Component, add the providers attribute and init the array with the services it needs…
@Component({
selector: ‘page-whatever’,
templateUrl: ‘whatever-page.html’,
providers: [ModalPlayer]
})
that is not the correct answer, as providers are now declared in the NgModules decorator.
Chances are, you forgot to add the Modal component to the declarations and entryComponents array in NgModules.
2 Likes
Thank you. This is working now.
I did not add modal component to the entryComponents
I had the same issue and solved it this way ( add the Modal component to the declarations and entryComponents array in NgModules). But shouldn’t “ionic generate page” do this automatically?
It’s something we’d like to add. Right now we have more important features/improvements to work on first
1 Like
@Daikinzan This is because you didn’t declare “ModalPlayer” modal ts file in app.module.js. So import modal file and include modal in declarations also entryComponents if needed.