5
升級到RC6(包括子路由),當我得到這個運行時錯誤與我的路由:子路由與RC6錯誤升級
ListingComponent是不是還沒有 被導入任何NgModule或模塊的一部分進入你的模塊
這個錯誤表明我沒有添加ListingComponent到ngModule,但它作爲一個聲明。
在app.module中,我將所有組件作爲聲明。我也導入我的路由組件。路由組件有一個名爲listing.routes的子路由組件。
這裏是我的app.module.ts:
import {NgModule, CUSTOM_ELEMENTS_SCHEMA, ReflectiveInjector } from '@angular/core';
import { BrowserModule } from '@angular/platform-browser';
import {FormsModule, FormBuilder} from '@angular/forms';
import { NgClass, NgStyle} from '@angular/common';
import { AppComponent } from './app.component';
import {routing} from './app.routes';
import {ListingModule} from './components/listing/listingmodule';
import {ListingComponent} from './components/listing/listing.Component';
@NgModule({
imports: [BrowserModule, routing],
providers: [],
declarations: [AppComponent, ListingComponent, ListingModule],
bootstrap: [AppComponent]
})
export class AppModule {
}
這裏是我的app.routes.ts(我導入爲路線):
import { ModuleWithProviders } from '@angular/core';
import { Routes, RouterModule } from '@angular/router';
import {ListingRoutes} from './components/listing/listing.routes';
import {SplashComponent} from './components/splash/splash.component';
export const appRoutingProviders: Routes = ([
{ path: '', component: SplashComponent },
{ path: 'login', component: SplashComponent },
...ListingRoutes
]);
export const routing: ModuleWithProviders = RouterModule.forRoot(appRoutingProviders);
這裏是我的listing.routes 。:
import { ModuleWithProviders } from '@angular/core';
import { Routes, RouterModule } from '@angular/router';
import {ListingModule} from './repairreturnmodule';
import {ListingComponent} from '../listing/listing.component';
export const ListingRoutes: Routes = [
{
path: '',
component: ListingModule,
children: [
{ path: 'listing', component: ListingComponent},
]
}
];
export const ListingRouting: ModuleWithProviders = RouterModule.forChild(ListingRoutes);
我錯過了什麼嗎?
好的。對不起,謝謝。我做了一個可能有用的編輯。這是否更好? – Pstr