Angular 角度4-导致错误的保护无法读取属性';创建';未定义的 我已经创建了一个保护(LoggedInGuard),我在AuthModule中定义了该保护,并将其导入我的AppModule 我还创建了一个仪表板模块,在他的路由模块中使用AuthModule中的LoggedGuard

Angular 角度4-导致错误的保护无法读取属性';创建';未定义的 我已经创建了一个保护(LoggedInGuard),我在AuthModule中定义了该保护,并将其导入我的AppModule 我还创建了一个仪表板模块,在他的路由模块中使用AuthModule中的LoggedGuard,angular,lazy-loading,angular-router,angular-router-guards,Angular,Lazy Loading,Angular Router,Angular Router Guards,在仪表板模块中使用LoggedInGuard时,它会导致: vendor.90461c1e81f8688ab265.bundle.js:1 Uncaught TypeError: Cannot read property 'create' of undefined at vendor.90461c1e81f8688ab265.bundle.js:1 at e.invoke (polyfills.f5a89f4a86af4d9fd561.bundle.js:1) at Ob

在仪表板模块中使用LoggedInGuard时,它会导致:

vendor.90461c1e81f8688ab265.bundle.js:1 Uncaught TypeError: Cannot read property 'create' of undefined
    at vendor.90461c1e81f8688ab265.bundle.js:1
    at e.invoke (polyfills.f5a89f4a86af4d9fd561.bundle.js:1)
    at Object.onInvoke (vendor.90461c1e81f8688ab265.bundle.js:1)
    at e.invoke (polyfills.f5a89f4a86af4d9fd561.bundle.js:1)
    at r.run (polyfills.f5a89f4a86af4d9fd561.bundle.js:1)
    at t.run (vendor.90461c1e81f8688ab265.bundle.js:1)
    at e._bootstrapModuleFactoryWithZone (vendor.90461c1e81f8688ab265.bundle.js:1)
    at e.bootstrapModuleFactory (vendor.90461c1e81f8688ab265.bundle.js:1)
    at Object.cDNt (main.fe03e438715300c2a840.bundle.js:1)
    at n (inline.ce435269133e3a18afdf.bundle.js:1)
import { AuthModule } from './auth'
import { AppRoutingModule } from './app.routing';
import { DashboardModule } from './dashboard/dashboard.module';

@NgModule({
  declarations: [
    AppComponent
  ],
  imports: [
    .....
    AuthModule,
    //routing order matters
    DashboardModule,
    AppRoutingModule
  ],
  providers: [],
  bootstrap: [AppComponent]
})
export class AppModule { }
注意-当我使用aot=false构建应用程序时,它工作正常

我的应用程序模块:

vendor.90461c1e81f8688ab265.bundle.js:1 Uncaught TypeError: Cannot read property 'create' of undefined
    at vendor.90461c1e81f8688ab265.bundle.js:1
    at e.invoke (polyfills.f5a89f4a86af4d9fd561.bundle.js:1)
    at Object.onInvoke (vendor.90461c1e81f8688ab265.bundle.js:1)
    at e.invoke (polyfills.f5a89f4a86af4d9fd561.bundle.js:1)
    at r.run (polyfills.f5a89f4a86af4d9fd561.bundle.js:1)
    at t.run (vendor.90461c1e81f8688ab265.bundle.js:1)
    at e._bootstrapModuleFactoryWithZone (vendor.90461c1e81f8688ab265.bundle.js:1)
    at e.bootstrapModuleFactory (vendor.90461c1e81f8688ab265.bundle.js:1)
    at Object.cDNt (main.fe03e438715300c2a840.bundle.js:1)
    at n (inline.ce435269133e3a18afdf.bundle.js:1)
import { AuthModule } from './auth'
import { AppRoutingModule } from './app.routing';
import { DashboardModule } from './dashboard/dashboard.module';

@NgModule({
  declarations: [
    AppComponent
  ],
  imports: [
    .....
    AuthModule,
    //routing order matters
    DashboardModule,
    AppRoutingModule
  ],
  providers: [],
  bootstrap: [AppComponent]
})
export class AppModule { }
我的AuthModule:

import { CommonModule } from '@angular/common';
import { AuthService } from './auth.service';
import { LoggedInGuard } from './login/login.guard';
import { LoginComponent } from './login/login.component';

import { AuthRoutingModule } from './auth-routing.module';
@NgModule({
    imports: [
        CommonModule,
        AuthRoutingModule

    ],
    declarations: [
        LoginComponent
    ],
    providers: [AuthService, LoggedInGuard],
    exports: [LoginComponent]
})

export class AuthModule {


}
我的仪表板路由:

import { NgModule } from '@angular/core';
import { RouterModule } from '@angular/router'; //import router module
import { DashboardComponent } from './dashboard.component';
import { HomeComponent } from './home/home.component';
import { LoggedInGuard } from '../auth/index';
import { AuthModule } from '../auth/auth.module';


 const dasboardRouting = RouterModule.forChild([


  {
    path: 'dashboard',
    component: DashboardComponent,
    children:[
      {path:'',component:HomeComponent},
      { path: 'game', loadChildren: './../game/game.module#GameModule' }//when route is 'lazy' -loading the lazy module

    ]
    ,canActivate: [LoggedInGuard]
  }


]);

@NgModule({
  imports: [
    AuthModule,
    dasboardRouting
  ],
  exports: [RouterModule],
  providers: [
      LoggedInGuard
  ]
})
export class DashboardRoutingModule {}

注意-我正在使用angular 4.2

尝试
{路径:'',组件:HomeComponent,路径匹配:'full'},
仍然不工作。-这是因为LoggedingGuard,当我将其从仪表板上移除时,它工作了,防护的来源丢失了。你是什么意思。你能举个例子吗?你的问题中不包括导致错误的防护装置的来源。你不认为这是你问题的中心部分吗?