错误:找不到[对象对象]的组件工厂 [英] Error: No component factory found for [object Object]

查看:91
本文介绍了错误:找不到[对象对象]的组件工厂的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我被困住了. 我知道通常如何解决该问题,但是这次我被困住了.

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?

为什么错误消息显示的是[object Object],而不是特定的组件?

Why the error message says [object Object], instead of specific component?

我知道错误在哪里,我知道是哪个代码引起的. 但是我不明白为什么会发生错误,为什么会显示[object Object].

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)我创建了一个组件,将其添加到declarationsentryCompoents中.现在,我试图将此组件用作来自同一模块的另一个组件的模式.

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.

我写了一个代码:

  openModal() {
    const modal = this.modalCtrl.create({
      component: SetLocationModal
    });

    modal.present();
    return false;
  }

<span (click)="openModal()">open modal</span>

并且执行失败

推荐答案

您发现您的代码仅适用于ionic v4.面对相同的问题,但又不想升级ionic,我发现此代码对我有用:

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:

在打开页面上:

async presentModal() {
    let modal = this.modalController.create(ModalNew);
    modal.onDidDismiss(data => {
      console.log(data);
    });
    modal.present();
  }

模式:

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

模式HTML

  <ion-header>
    <ion-toolbar>
    <h1 class="title">My Modal title</h1>
    </ion-toolbar>
  </ion-header>
  <ion-content padding>
  </ion-content>

此答案基于: https://ionicframework.com/docs/v3/api/components/modal/ModalController/

这篇关于错误:找不到[对象对象]的组件工厂的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆