gpt4 book ai didi

angular - 在 ionic3 中延迟加载,但错误 : No component factory found

转载 作者:太空狗 更新时间:2023-10-29 18:06:50 25 4
gpt4 key购买 nike

我在 ionic3 中使用延迟加载,但是当它服务时,浏览器显示错误:

Failed to navigate: No component factory found for TabsPage. Did you add it to @NgModule.entryComponents?

这是我的代码:

应用程序模块.ts

@NgModule({
declarations: [
MyApp,
FormModal,
PreviewModal,
],
imports: [
BrowserModule,
HttpModule,
JsonpModule,
CommonModule,
IonicModule.forRoot(MyApp)
],
bootstrap: [IonicApp],
entryComponents: [
MyApp,
],
providers: [
Router,
StatusBar,
SplashScreen,
ApiService,
Toast,
Loading,
Alert,
UserService,
ChangeTitle,
ParseLogin,
{provide: ErrorHandler, useClass: IonicErrorHandler}
]
})
export class AppModule {}

应用程序组件.ts

@Component({
templateUrl: 'app.html'
})
export class MyApp {

rootPage:any = "TabsPage";

constructor(platform: Platform, statusBar: StatusBar, splashScreen: SplashScreen,router:Router) {
router.setVersion('1.0',10000);
router.load(Routes);
Event.subscribe('push',(ev,data)=>{
document.title =Routes[data.toPage.name].title;
var i = document.createElement('iframe');
i.src = 'blank.html';
i.style.display = 'none';
i.onload = function() {
setTimeout(function(){
i.remove();
}, 9)
}
document.body.appendChild(i);


})
Event.subscribe('pop',(ev,data)=>{
if(!data.toPage.name||!Routes[data.toPage.name])return;//这里应该关闭微信页面
document.title =Routes[data.toPage.name].title;
var i = document.createElement('iframe');
i.src = 'blank.html';
i.style.display = 'none';
i.onload = function() {
setTimeout(function(){
i.remove();
}, 9)
}
document.body.appendChild(i);
console.log(data);
})
platform.ready().then(() => {
statusBar.styleDefault();
splashScreen.hide();
});
}
}

tabs.html

<ion-tabs selectedIndex="{{selectedIndex}}">
<ion-tab [root]="tab1Root" tabTitle="发现" tabIcon="eye" (ionSelect)="chat('发现')"></ion-tab>
<ion-tab [root]="tab2Root" tabTitle="活动" tabIcon="paper-plane" (ionSelect)="chat('活动')"></ion-tab>
<ion-tab [root]="tab3Root" tabTitle="君读" tabIcon="book" (ionSelect)="chat('君读')"></ion-tab>
<ion-tab [root]="tab4Root" tabTitle="我" tabIcon="person" (ionSelect)="chat('我')"></ion-tab>
</ion-tabs>

tabs.module.ts

import { NgModule } from '@angular/core';
import { IonicPageModule } from 'ionic-angular';
import { TabsPage } from './tabs';

@NgModule({
declarations: [
TabsPage,
],
imports: [
IonicPageModule.forChild(TabsPage)
],
exports: [
TabsPage
]
})
export class TabsPageModule {}

标签.ts

import { Component} from '@angular/core';
import { NavParams ,IonicPage} from 'ionic-angular';
import{ChangeTitle} from"../../components/changeTitle"

@IonicPage()
@Component({
templateUrl: 'tabs.html'
})

export class TabsPage {

tab1Root = "FinderPage";
tab2Root = "ListPage";
tab3Root = "ArticleListPage";
tab4Root = "UserPage";
selectedIndex:string='0';

constructor(public changeTitle:ChangeTitle,public navParams: NavParams) {
this.selectedIndex=this.navParams.get("index");
if (!this.selectedIndex){
this.selectedIndex = '0'; // 默认发现首页
}
}
chat(title){
console.log(title);
this.changeTitle.changeDomTitle(title);
}
}

但是在我运行 comman : ‘ionic serve’ 之后,我的浏览器显示错误:

Failed to navigate: No component factory found for TabsPage. Did you add it to @NgModule.entryComponents?

最佳答案

您需要在 TabsPageModule 的 entryComponents 数组中设置页面。目前您已在 exports 数组中设置。 exports 是允许一个模块/组件在其他模块中使用。

@NgModule({
declarations: [
TabsPage,
],
imports: [
IonicPageModule.forChild(TabsPage)
],
entryComponents: [
TabsPage //here
]
})

关于angular - 在 ionic3 中延迟加载,但错误 : No component factory found,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/46108288/

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