我是Angular 2的新手我需要路由部分的帮助。我正在使用http://jasonwatmore.com/post/2016/09/29/angular-2-user-registration-and-login-example-tutorial
我收到了错误
导出变量'routing'在外部模块“/ home / frank / angular / node_modules / @ angular / core / src / metadata / ng_module”中使用或正在使用名称'ModuleWithProviders',但无法命名。
这是我的代码
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 { }
有关错误的任何想法?我还尝试了来自'@ angular / core'的seimport {ModuleWithProviders};关于我的“声明”:是的,在tsconfig.js中也是导入的
答案 0 :(得分:6)
我通过以下方式解决了这个问题:
export const routing: ModuleWithProviders = RouterModule.forRoot(APP_ROUTES);
并且不要忘记从@ angular / core
导入ModuleWithProvidersimport { ModuleWithProviders } from "@angular/core";
答案 1 :(得分:3)
您不需要导入ModuleWithProviders
。我认为您只需要在较旧的Release Candiades(RCs)中导入该模块。目前,导入MgModule
会自动允许提供商,这似乎是ModuleWithProviders
DOCS