升级到角度4 ERROR后出错无法使用' in'运营商搜索提供商'在null

时间:2017-04-28 07:44:47

标签: angular angular2-routing angular-cli

更新到角度4后,我总是在使用angular-cli构建时遇到相同的错误:

ERROR in Cannot use 'in' operator to search for 'providers' in null 

这是我的app.modules.ts:

const authenticatedRoutes: Route[] = [
      {
        path: 'app',
        component: TsComponent,
        children: routingConfig
      },
      { path: '**', redirectTo: 'app/cockpit', pathMatch: 'full' }
    ];

const routes: Route[] = [
  { path: 'login', component: LoginComponent, canActivate: [StartupActivationGuard] }
];

@NgModule({
  declarations: [
    AppComponent,
    LoginComponent
  ],
  imports: [
    BrowserModule,
    FormsModule,
    GlobalSharedModule.forRoot(),
    TsModule,
    AuthModule.forRoot(),
    StartupModule.forRoot(),
    MaterialModule,
    RouterModule.forRoot(routes)
  ],
  providers: [
    { provide: ErrorHandler , useClass: TimeShepherdExceptionHandler }
  ],
  entryComponents: [AppComponent],
  bootstrap: [AppComponent]
})
export class AppModule {

}


authenticatedRoutes.reduce((routeCollection, route: Route) => {
  route.canActivate = defaultGuards;
  routeCollection.push(route);
  return routeCollection;
}, routes);

const appRouterProviders = RouterModule.forRoot(routes);

这是我的app.routes.ts:

const defaultGuards: any[] = [
  AuthActivationGuard
];

const authenticatedRoutes: Route[] = [
  { path: '', redirectTo: 'app/cockpit', pathMatch: 'full' },
  {
    path: 'app',
    component: TsComponent,
    children: routingConfig
  },
  { path: '**', redirectTo: 'app/cockpit', pathMatch: 'full' }
];

const routes: Route[] = [
  { path: 'login', component: LoginComponent, canActivate: [StartupActivationGuard] }
];

authenticatedRoutes.reduce((routeCollection, route: Route) => {
  route.canActivate = defaultGuards;
  routeCollection.push(route);
  return routeCollection;
}, routes);

export const appRouterProviders = RouterModule.forRoot(routes);

我还在另一个目录ts / ts.routes.ts中使用子路由:

export const routingConfig = [
  { path: 'start', component: StartComponent },
  { path: 'logbook', component: LogBookComponent },
  { path: 'example', component: ExampleComponent },
  { path: 'dev', component: DevComponent },
  { path: 'journal', component: JournalComponent},
  { path: 'cockpit', component: CockpitComponent},
  { path: 'reports', component: ReportsComponent}
];
export const routing = RouterModule.forChild(routingConfig);

我知道为什么会收到错误?

0 个答案:

没有答案