意外的价值' LoginRoutingModule'由模块导入的“登录模块”'

时间:2017-03-05 07:38:06

标签: angular

您好,作为Angular 2学习项目的一部分,我正在创建一个测试应用程序。

我正急切地加载一个名为LoginModule的模块但是我收到了以下错误 意外的价值' LoginRoutingModule'由模块' LoginModule'

导入

我试图引用其他问题,其中错误信息与上述类似但是没有任何帮助我。

如果有人可以帮我解决问题,那将会很棒。

我的目录结构如下

enter image description here

login.module.ts就像这样

import { NgModule } from '@angular/core';
import { CommonModule } from '@angular/common';

import { LoginRoutingModule, loginRoutableComponents } from './login-routing.module';

@NgModule({
    imports: [
        CommonModule,
        LoginRoutingModule ],
    declarations: [ loginRoutableComponents ],
})
export class LoginModule{ }

login-routing.module.ts如下

import { NgModule } from '@angular/core';
import { RouterModule, Routes } from '@angular/router';

import { LoginComponent } from './login.component';

const routes: Routes = [
    { path: 'login', component: LoginComponent }
];

NgModule({
    imports: [ RouterModule.forChild(routes) ],
    exports: [ RouterModule ],
})
export class LoginRoutingModule{ }

export const loginRoutableComponents = [
    LoginComponent
];

app.module.ts如下

import { NgModule } from '@angular/core';
import { BrowserModule } from '@angular/platform-browser';
import { FormsModule } from '@angular/forms';
import { RouterModule } from '@angular/router';

import { AppComponent }  from './app.component';

import { ToastModule } from './core/toast/toast.module';
import { ModalModule } from './core/modal/modal.module';
import { SpinnerModule } from './core/spinner/spinner.module';

import { CharacterModule } from './characters/character.module';
import { DashboardModule } from './dashboard/dashboard.module';
import { VehiclesModule } from './vehicles/vehicles.module';

import { LoginModule } from './login/login.module';

import { AppRoutingModule, appRoutableComponents } from './app-routing.module';

@NgModule({
  imports:      [ BrowserModule,
                  FormsModule,
                  RouterModule,
                  ToastModule,
                  ModalModule,
                  SpinnerModule,
                  DashboardModule,
                  CharacterModule,
                  VehiclesModule,
                  LoginModule,
                  AppRoutingModule
                ],
  declarations: [ AppComponent,
                  appRoutableComponents,
                ],
  bootstrap:    [ AppComponent ],
})
export class AppModule { }

app-routing.module.ts如下

import { NgModule } from '@angular/core';
import { Routes, RouterModule } from '@angular/router';

import { PageNotFoundComponent } from './page-not-found.component';
const routes: Routes = [
    { path: '', pathMatch: 'full', redirectTo: 'dashboard' },
    { path: '**', component: PageNotFoundComponent }
]


@NgModule({
    imports: [ RouterModule.forRoot(routes) ],
    exports: [ RouterModule ]
})
export class AppRoutingModule { }

export const appRoutableComponents = [
    PageNotFoundComponent
];

1 个答案:

答案 0 :(得分:1)

你错过了这个组件中的NgModule之前的@

login-routing.module.ts is as follows

import { NgModule } from '@angular/core';
import { RouterModule, Routes } from '@angular/router';

import { LoginComponent } from './login.component';

const routes: Routes = [
    { path: 'login', component: LoginComponent }
];
//////////////////////////////////////////////////////////////////////
@NgModule({
//////////////////////////////////////////////////////////////////////
    imports: [ RouterModule.forChild(routes) ],
    exports: [ RouterModule ],
})
export class LoginRoutingModule{ }

export const loginRoutableComponents = [
    LoginComponent
];