2016-09-08 63 views
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); 

我錯過了什麼嗎?

回答

0

編輯:您如果使用來自AppComponent相同的約定(你應該),你應該從

import {ListingComponent} from './components/listing/listing.component'; 

導入看看是名來自

import {ListingComponent} from './components/listing/listing.Component'; 

導入您ListingComponent文件。其餘的代碼看起來是正確的。


我不知道這是否是問題的根源,但你在那裏的AppModule聲明模塊,當你要導入它... 嘗試從聲明數組ListingModule移動進口數組。

+0

好的。對不起,謝謝。我做了一個可能有用的編輯。這是否更好? – Pstr