我试图在我的angular4项目中创建一个延迟加载,按照文档中的所有步骤操作,什么都不做。
下面是我的代码:
学生模块:
import { NgModule } from '@angular/core';
import { CommonModule } from '@angular/common';
import { StudentComponent } from './student.component';
import { StudentNotFoundComponent } from './student-not-found/student-not-found.component';
import { StudentFormComponent } from './student-form/student-form.component';
import { StudentDetailComponent } from './student-detail/student-detail.component';
import { StudentService } from './student.service';
@NgModule({
imports: [
CommonModule
],
declarations: [
StudentComponent,
StudentFormComponent,
StudentDetailComponent,
StudentNotFoundComponent
],
providers: [
StudentService
]
})
export class StudentModule { }
学生路线模块:
import { ModuleWithProviders } from '@angular/core';
import { NgModule } from '@angular/core';
import { RouterModule, Routes } from '@angular/router';
import { StudentNotFoundComponent } from './student-not-found/student-not-found.component';
import { StudentFormComponent } from 'app/student/student-form/student-form.component';
import { StudentDetailComponent } from './student-detail/student-detail.component';
import { StudentComponent } from './student.component';
const student : Routes = [
{path : '', component : StudentComponent, children: [
{path : 'new', component : StudentFormComponent},
{path : ':id', component : StudentDetailComponent},
{path : ':id/edit', component : StudentFormComponent},
{path : 'student-not-found', component : StudentNotFoundComponent}
]}
];
@NgModule({
imports : [RouterModule.forChild(student)],
exports : [RouterModule]
})
export class SchoolClassRoutingModule { }
批准模块:
import { ModuleWithProviders } from '@angular/core';
import { RouterModule, Routes, LoadChildren } from '@angular/router';
import { NgModule } from '@angular/core';
import { HomeComponent } from './home/home.component';
import { PageNotFoundComponent } from './page-not-found/page-not-found.component';
import { AuthGuard } from './guard/auth.guard';
const APP_ROUTE: Routes = [
{
path: 'student',
component: StudentComponent,
loadChildren: 'app/student/student.module#StudentModule',
canLoad: [AuthGuard]
},
{ path: 'login', component: LoginComponent},
{ path: 'home', component: HomeComponent},
{ path: '', redirectTo: 'home', pathMatch: 'full' },
{ path: '**', component: PageNotFoundComponent}
];
@NgModule({
imports : [RouterModule.forRoot(APP_ROUTE)],
exports : [RouterModule]
})
export class AppRoutingModule { }
和AppModule:
import { BrowserModule } from '@angular/platform-browser';
import { NgModule } from '@angular/core';
import { FormsModule } from '@angular/forms';
import { HttpModule } from '@angular/http';
import { ModuleWithProviders } from '@angular/core';
import { MaterializeModule } from 'angular2-materialize';
import { AppComponent } from './app.component';
import { LoggedConfig } from './config/logged.config';
import { TokenConfig } from './config/token.config'
import { AuthGuard } from './guard/auth.guard';
import { AuthenticationService } from './authentication/authentication.service';
import { LoginComponent } from './login/login.component';
import { AdministratorComponent } from './administrator/administrator.component';
import { HomeComponent } from './home/home.component';
import { NavbarComponent } from './navbar/navbar.component';
import { PageNotFoundComponent } from './page-not-found/page-not-found.component';
import { AppRoutingModule } from 'app/app.routing.module';
@NgModule({
declarations: [
AppComponent,
LoginComponent,
AdministratorComponent,
HomeComponent,
NavbarComponent,
PageNotFoundComponent
],
imports: [
BrowserModule,
FormsModule,
HttpModule,
MaterializeModule,
AppRoutingModule
],
providers: [
AuthGuard,
AuthenticationService,
LoggedConfig,
TokenConfig
],
bootstrap: [AppComponent]
})
export class AppModule { }
控制台错误:
Console error
我已经阅读了文档,我已经在github中看到了几个示例,所有这些都是我正在做的事情。帮助