我正在使用 Ionic Framework(版本 5)開發基于選項卡的應用程式。只有當我修改代碼并且應用程式在“主頁”以外的頁面上自動重新加載時才會出現以下錯誤。

我已經嘗試將模塊匯入到每個頁面的模塊類CommonModule中FormsModule,IonicModule但不起作用,使指令像ngFor作業一樣的解決方法是在主頁上重新加載應用程式。
具體來說,此錯誤發生在頁面中new-article:
src/app/pages/new-article/new-article.page.html
<ion-grid>
<ion-row>
<ion-col *ngFor="let url of artcile.photos"><img [src]="url"/></ion-col>
</ion-row>
</ion-grid>
src/app/pages/new-article/new-article.module.ts
@NgModule({
imports: [
CommonModule,
FormsModule,
IonicModule,
NewArticlePageRoutingModule
],
declarations: [NewArticlePage]
})
export class NewArticlePageModule {}
正如我之前所說,它是一個基于選項卡的應用程式,所有頁面都通過路由模塊處理:
src/app/tabs/tabs-routing.module.ts
const routes: Routes = [
{
path: 'tabs',
component: TabsPage,
children: [
{
path: 'home',
loadChildren: () => import('../pages/home/home.module').then(m => m.HomePageModule)
},
...
{
path: 'new-article',
loadChildren: () => import('../pages/new-article/new-article-routing.module').then(m => m.NewArticlePageRoutingModule)
},
{
path: '',
redirectTo: '/tabs/home',
pathMatch: 'full'
}
]
},
{
path: '',
redirectTo: '/tabs/home',
pathMatch: 'full'
}
];
如果有人對此有任何建議,我將不勝感激。
更新
當您 importcomponent-routing.module而不是component.moduleinto時,可能會發生此錯誤tabs-routing.module.ts。
uj5u.com熱心網友回復:
你的 app.module.ts 里有這個嗎?
import { BrowserModule } from '@angular/platform-browser';
@ngModule({imports:[Browsermodule]})
如果不添加它。
如果您已經添加了此內容,請編輯您的問題,以便它包含有關您的問題背景關系的更多資訊。
uj5u.com熱心網友回復:
我認為問題在于您在選項卡路由模塊中匯入了新文章頁面的路由模塊,而您實際上應該在其中匯入新文章頁面的基本模塊。在 內tabs-routing.module.ts,更改此內容:
{
path: 'new-article',
loadChildren: () => import('../pages/new-article/new-article-routing.module').then(m => m.NewArticlePageRoutingModule)
},
對此:
{
path: 'new-article',
loadChildren: () => import('../pages/new-article/new-article-page.module').then(m => m.NewArticlePageModule)
},
我希望能為您解決這個問題。
uj5u.com熱心網友回復:
您必須在路由中加載組件模塊,而不是路由模塊:
{
path: 'new-article',
loadChildren: () => import('../pages/new-article/new-article.module').then(m => m.NewArticlePageModule)
},
這是在 Angular 應用程式中使用路由的正確方法。
轉載請註明出處,本文鏈接:https://www.uj5u.com/houduan/534488.html
標籤:有角度的打字稿离子框架
上一篇:視窗子句的決議作用及手段
