2016-12-14 30 views
2

enter image description hereModuleWithProviders提供的角度2路由錯誤

我是Angular 2中的新成員我需要路由部分的幫助。我使用http://jasonwatmore.com/post/2016/09/29/angular-2-user-registration-and-login-example-tutorial

我得到一個錯誤

出口變量「路由」已經或正在使用的名稱「ModuleWithProviders」從外部模塊「的/ home /坦白/角/ node_modules/@角/核心/ src/metadata/ng_module「,但無法命名。

這裏是我的代碼

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}; tting我的「聲明」:true,在tsconfig.js中,也導入

+1

你可以顯示'app.routing'文件。看起來這是錯誤來自的地方 –

回答

5

的唯一目的,我這樣做解決了這個:

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

而且不要忘了從@角/核心

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

您不應該導入ModuleWithProviders。我認爲你只需要在舊版本的Candiades(RC)中導入該模塊。目前,進口MgModule將自動允許這似乎提供商成爲ModuleWithProvidersDOCS