问题
I'm stuck. I know how to usually deal with the problem, but this time I'm stuck.
1) Error: Uncaught (in promise): Error: No component factory found for [object Object]. Did you add it to @NgModule.entryComponents?
Why the error message says [object Object]
, instead of specific component?
I know where is the error, I know which code is causing it.
But I do not understand WHY the error occurs and WHY it says [object Object]
.
2) I have created a component, I have added it to declarations
and to the entryCompoents
. Now I am trying to use this component as a modal from another compoent of the same module.
I wrote a code:
openModal() {
const modal = this.modalCtrl.create({
component: SetLocationModal
});
modal.present();
return false;
}
<span (click)="openModal()">open modal</span>
and it fails to execute
回答1:
As you found out your code works only for ionic v4. Facing the same problem and not wanting to upgrade ionic just yet I found this code working for me:
On opening page:
async presentModal() {
let modal = this.modalController.create(ModalNew);
modal.onDidDismiss(data => {
console.log(data);
});
modal.present();
}
modal:
import { Component } from '@angular/core';
import {ViewController} from "ionic-angular";
@Component({
selector: 'new-time',
templateUrl: 'new.html'
})
export class ModalNew {
constructor(public viewCtrl: ViewController) {
// componentProps can also be accessed at construction time using NavParams
}
}
modal html
<ion-header>
<ion-toolbar>
<h1 class="title">My Modal title</h1>
</ion-toolbar>
</ion-header>
<ion-content padding>
</ion-content>
This answer is based on: https://ionicframework.com/docs/v3/api/components/modal/ModalController/
回答2:
What is the type of modalCtrl? a MatDialog? or other? I have implemented in previous projects and remember doing 'open' not create
this.modalCtrl.open(RequestCardComponent, {/*any data to pass to the component*/});
来源:https://stackoverflow.com/questions/54726116/error-no-component-factory-found-for-object-object