Fra*_*dez 3 angular2-routing angular2-modules angular

我是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 { }
Run Code Online (Sandbox Code Playgroud)
关于错误的任何想法?我还尝试了来自'@ angular/core'的seimport {ModuleWithProviders};我的"声明":在tsconfig.js中也是真的,也是导入的
小智 7
我解决了这个问题:
export const routing: ModuleWithProviders = RouterModule.forRoot(APP_ROUTES);
Run Code Online (Sandbox Code Playgroud)
并且不要忘记从@ angular/core导入ModuleWithProviders
import { ModuleWithProviders } from "@angular/core";
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
5806 次 |
| 最近记录: |