【发布时间】:2019-03-02 17:29:48
【问题描述】:
我有一个带有 Angular 6 模板应用程序的 Ionic 3,我正在尝试将用户重定向到另一个页面(点击时)。我不断收到此错误消息
Uncaught (in promise): Error: No component factory found for GoogleCardLayout2. Did you add it to @NgModule.entryComponents?
Error: No component factory found for GoogleCardLayout2. Did you add it to @NgModule.entryComponents?
at noComponentFactoryError
我不确定这意味着什么。在我的“.ts”文件中,我导入了第二页
import { GoogleCardLayout2 } from '../layout-2/google-card-layout-2';
并且还设置了一个将用户推送到下一页的功能
openTestpage() {
this.navCtrl.push(GoogleCardLayout2);
}
但我只是不断遇到错误。这是我的html、ts和模块代码
HTML
<div watch-now text-center (click)="openTestpage()">
<button ion-button button-icon icon-start>
<ion-icon icon-small [name]="item.icon"></ion-icon>
{{item.iconText}}
</button>
</div>
TS 文件
import { Component, Input, ViewChild } from '@angular/core';
import { IonicPage, Content, NavController } from 'ionic-angular';
import { GoogleCardLayout2 } from '../layout-2/google-card-layout-2';
@IonicPage()
@Component({
selector: 'google-card-layout-1',
templateUrl: 'google-card.html'
})
export class GoogleCardLayout1 {
@Input() data: any;
@Input() events: any;
@ViewChild(Content)
content: Content;
slider = {};
constructor(public navCtrl: NavController) {
}
openTestpage() {
this.navCtrl.push(GoogleCardLayout2);
}
}
模块 TS 文件
import { NgModule, CUSTOM_ELEMENTS_SCHEMA } from '@angular/core';
import { IonicPageModule } from 'ionic-angular';
import { GoogleCardLayout1 } from './google-card-layout-1';
@NgModule({
declarations: [
GoogleCardLayout1,
],
imports: [
IonicPageModule.forChild(GoogleCardLayout1),
],
exports: [
GoogleCardLayout1
],
schemas: [CUSTOM_ELEMENTS_SCHEMA]
})
export class GoogleCardLayout1Module { }
app.module.ts
import { NgModule, ErrorHandler, CUSTOM_ELEMENTS_SCHEMA } from '@angular/core';
import { IonicApp, IonicModule, IonicErrorHandler } from 'ionic-angular';
import { BrowserModule } from '@angular/platform-browser';
import { MyApp } from './app.component';
import { AngularFireModule } from 'angularfire2';
import { AngularFireDatabaseModule } from 'angularfire2/database';
import { AngularFirestoreModule } from 'angularfire2/firestore';
import { AngularFireAuthModule } from 'angularfire2/auth';
import { AppSettings } from '../services/app-settings'
import { ToastService } from '../services/toast-service'
import { LoadingService } from '../services/loading-service'
import { StatusBar } from '@ionic-native/status-bar';
import { SplashScreen } from '@ionic-native/splash-screen';
import { HttpClientModule } from '@angular/common/http';
@NgModule({
declarations: [
MyApp
],
imports: [
BrowserModule,
HttpClientModule,
IonicModule.forRoot(MyApp),
AngularFireModule.initializeApp(AppSettings.FIREBASE_CONFIG),
AngularFireDatabaseModule, AngularFireAuthModule, AngularFirestoreModule
],
bootstrap: [IonicApp],
entryComponents: [MyApp],
schemas: [CUSTOM_ELEMENTS_SCHEMA],
providers: [
StatusBar, SplashScreen,
ToastService, LoadingService,
{ provide: ErrorHandler, useClass: IonicErrorHandler }]
})
export class AppModule {
}
GoogleCardLayout2 模块
import { NgModule, CUSTOM_ELEMENTS_SCHEMA } from '@angular/core';
import { IonicPageModule } from 'ionic-angular';
import { GoogleCardLayout2 } from './google-card-layout-2';
@NgModule({
declarations: [
GoogleCardLayout2,
],
imports: [
IonicPageModule.forChild(GoogleCardLayout2),
],
exports: [
GoogleCardLayout2
],
schemas: [CUSTOM_ELEMENTS_SCHEMA]
})
export class GoogleCardLayout2Module { }
【问题讨论】:
-
您好,欢迎来到 SO。你能分享你的 app.module.ts 吗?还有 - 您是否对页面/组件使用延迟加载?
-
我正在使用我在网站上找到的模板,所以我不确定他们是否这样做,是的,我可以
标签: javascript html angular ionic-framework ionic3