gpt4 book ai didi

angular - @NgModule.entryComponents 错误

转载 作者:搜寻专家 更新时间:2023-10-30 21:29:08 25 4
gpt4 key购买 nike

我有一个代码:

////////////////login.module.ts
import { NgModule } from '@angular/core';
import { IonicPageModule } from 'ionic-angular';
import { LoginPage } from './login';

@NgModule({
declarations: [
LoginPage,
],
imports: [
IonicPageModule.forChild(LoginPage),
],
})
export class LoginPageModule {}

////////////////// login.ts
import { Component } from '@angular/core';
import { IonicPage, NavController, NavParams } from 'ionic-angular';

@IonicPage()
@Component({
selector: 'page-login',
templateUrl: 'login.html',
})
export class LoginPage {
constructor(public navCtrl: NavController, public navParams: NavParams) {
}

ionViewDidLoad() {
console.log('ionViewDidLoad LoginPage');
}

doLogin(){
this.navCtrl.setRoot('SpecialPage')
}
}

/////////////////login.html
<ion-content padding>
<button ion-button full (click)="doLogin()">Login</button>
</ion-content>


//////////////// special.module.ts
import { NgModule } from '@angular/core';
import { IonicPageModule } from 'ionic-angular';
import { SpecialPage } from './special';
import { HomePage } from '../home/home';

@NgModule({
declarations: [
SpecialPage,
HomePage
],
entryComponents: [
SpecialPage,
HomePage
],
imports: [
IonicPageModule.forChild(SpecialPage),
],
})
export class SpecialPageModule {}

//////////////// special.ts
import { Component } from '@angular/core';
import { IonicPage, NavController, NavParams } from 'ionic-angular';

import { HomePage } from '../home/home';

@IonicPage()
@Component({
selector: 'page-special',
templateUrl: 'special.html',
})
export class SpecialPage {
tab1Root = HomePage;
myIndex : number;

constructor(public navCtrl: NavController, public navParams: NavParams) {
}

ionViewDidLoad() {
console.log('ionViewDidLoad SpecialPage');
}
}

/////////////////// special.html
<ion-tabs [selectedIndex]="myIndex">
<ion-tab [root]="tab1Root" tabTitle="Home" tabIcon="home"></ion-tab>
</ion-tabs>

/////////////// home.ts
import { Component } from '@angular/core';
import { NavController } from 'ionic-angular';

@Component({
selector: 'page-home',
templateUrl: 'home.html'
})
export class HomePage {
constructor(public navCtrl: NavController) {
}
}

And I get a error: Runtime Error Uncaught (in promise): Error: No component factory found for HomePage. Did you add it to @NgModule.entryComponents? Error: No component factory found for HomePage. Did you add it to @NgModule.entryComponents? at noComponentFactoryError (http://localhost:8101/build/vendor.js:3682:34) at _NullComponentFactoryResolver.resolveComponentFactory (http://localhost:8101/build/vendor.js:3700:15) at CodegenComponentFactoryResolver.resolveComponentFactory

请帮忙 出了什么问题,我将 home 包含在 entryComponents 中。反正有错误

最佳答案

您需要从 special.module.ts 模块中删除 HomePage。您应该只将它添加到 app.module.ts 中,因为您没有对 home 组件使用延迟加载

special.module.ts

import { NgModule } from '@angular/core';
import { IonicPageModule } from 'ionic-angular';
import { SpecialPage } from './special';
//import { HomePage } from '../home/home'; --> remove this

@NgModule({
declarations: [
SpecialPage,
//HomePage --> remove this
],
entryComponents: [
SpecialPage,
//HomePage --> remove this
],
imports: [
IonicPageModule.forChild(SpecialPage),
],
})
export class SpecialPageModule {}

关于angular - @NgModule.entryComponents 错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/45997898/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com