angular2 rc.5angular2路線類型錯誤:無法讀取屬性「forRoot」
我得到TypeError: Cannot read property 'forRoot' of undefined(…)
當我調查我發現,RouterModule
是在執行過程中undefined
。
以下是我app.route.ts
import {Routes, RouterModule } from '@angular/router';
//const routes: Routes = [];
import {HelloComponent} from './hello.component';
import {IncComponent} from './inc.component';
import {AdditionComponent} from './addition.component';
import {RomanComponent} from './roman.component';
let routes: Routes = [
{
path: 'hello',
component: HelloComponent
},
{
path: '',
redirectTo: '/hello',
pathMatch: 'full'
},
{
path: 'increment',
component: IncComponent
},{
path: 'adder',
component: AdditionComponent
},{
path: 'roman',
component: RomanComponent
}
];
export const routing = RouterModule.forRoot(routes); // error on this line
以下是我app.module.ts
import { NgModule } from '@angular/core';
import { BrowserModule } from '@angular/platform-browser';
import { AppComponent } from './app.component';
import {routing} from './app.routes';
import {HelloComponent} from './hello.component';
import {IncComponent} from './inc.component';
import {AdditionComponent} from './addition.component';
import {RomanComponent} from './roman.component';
@NgModule({
imports:[
BrowserModule,
routing
],
declarations: [
AppComponent,
HelloComponent,
IncComponent,
AdditionComponent,
RomanComponent
],
bootstrap: [ AppComponent ]
})
export class AppModule { }
和main.ts
import { platformBrowserDynamic } from '@angular/platform-browser-dynamic';
//import { HTTP_PROVIDERS } from '@angular/http';
import { AppModule } from './app.module';
platformBrowserDynamic().bootstrapModule(AppModule);
可能的原因js文件是你'systemjs.config.js'文件沒有'路由器module'參考。 – micronyks
你必須只在蹲下生產。在RC5之後,事情變得難以理解。 – micronyks
你找到解決方案嗎? – Yvan