angular2-routing – 使用RC6升级的子路由错误
发布时间:2020-12-17 18:05:21 所属栏目:安全 来源:网络整理
导读:升级到RC6时,我的路由器出现运行时错误(包括子路由): ListingComponent is not part of any NgModule or the module has not been imported into your module 此错误表示我没有将ListingComponent添加到ngModule,但它作为声明存在. 在app.module中,我将所有
升级到RC6时,我的路由器出现运行时错误(包括子路由):
此错误表示我没有将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',...ListingRoutes ]); export const routing: ModuleWithProviders = RouterModule.forRoot(appRoutingProviders); 这是我的listing.routes.ts: 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); 我错过了什么吗? 解决方法
编辑:您正在从中导入您的ListingComponent
import {ListingComponent} from './components/listing/listing.Component'; 如果你使用AppComponent中的相同约定(你应该),你应该从中导入 import {ListingComponent} from './components/listing/listing.component'; 看看文件的名称是什么.其余代码看起来正确. 我不确定这是否是问题的根源,但你在AppModule中声明了一个模块,当你应该导入它时……尝试将ListingModule从声明数组移动到imports数组. (编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |