Angular 2 ModuleWithProviders 的路由错误

Angular 2 Routing Error with ModuleWithProviders

我是 Angular 2 的新人,我需要有关路由部分的帮助。我正在使用 http://jasonwatmore.com/post/2016/09/29/angular-2-user-registration-and-login-example-tutorial

我收到一个错误

Exported variable 'routing' has or is using name 'ModuleWithProviders' from external module "/home/frank/angular/node_modules/@angular/core/src/metadata/ng_module" but cannot be named.

这是我的代码

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

// used to create fake backend
import { fakeBackendProvider } from './_helpers/index';
import { MockBackend, MockConnection } from '@angular/http/testing';
import { BaseRequestOptions } from '@angular/http';

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

import { AlertComponent } from './_directives/index';
import { AuthGuard } from './_guards/index';
import { AlertService, AuthenticationService, UserService } from './_services/index';
import { HomeComponent } from './home/index';
import { LoginComponent } from './login/index';
import { RegisterComponent } from './register/index';

@NgModule({
    imports: [
    BrowserModule,
    FormsModule,
    HttpModule,
    routing
 ],
declarations: [
AppComponent,
AlertComponent,
HomeComponent,
LoginComponent,
RegisterComponent
],
providers: [
    AuthGuard,
    AlertService,
    AuthenticationService,
    UserService,

    // providers used to create fake backend
    fakeBackendProvider,
    MockBackend,
    BaseRequestOptions
],
bootstrap: [AppComponent]
})

 export class AppModule { }

关于这个错误有什么想法吗?我还尝试了 seimport { ModuleWithProviders } from '@angular/core';tting my "declaration": true, in tsconfig.js 并且还导入了

您应该不需要导入 ModuleWithProviders。我认为您只需要在较旧的 Release Candiades (RC) 中导入该模块。目前,导入 MgModule 将自动允许提供程序,这似乎是 ModuleWithProviders DOCS

的唯一目的

我通过以下方式解决了这个问题:

export const routing: ModuleWithProviders = RouterModule.forRoot(APP_ROUTES);

并且不要忘记从@angular/core

导入 ModuleWithProviders
import { ModuleWithProviders } from "@angular/core";