2016-10-17 41 views
3

試圖建立路由首次角2(路由器3.0.0)參數類型{路徑:串,組分HomeComponent} []是不能分配給參數類型路由

import { BrowserModule } from '@angular/platform-browser'; 
import { NgModule } from '@angular/core'; 
import { FormsModule } from '@angular/forms'; 
import { HttpModule } from '@angular/http'; 
import { RouterModule} from '@angular/router'; 
import { AppComponent } from './app.component'; 
import { BoardComponent } from './board/board.component'; 
import { HomeComponent } from './home/home.component'; 

@NgModule({ 
    declarations: [ 
    AppComponent, 
    BoardComponent, 
    HomeComponent 
    ], 
    imports: [ 
    BrowserModule, 
    FormsModule, 
    HttpModule, 
    RouterModule.forRoot([ 
     { path: '', component: HomeComponent } 
    ]) 
    ], 
    providers: [], 
    bootstrap: [AppComponent] 
}) 
export class AppModule { } 

我得到的上錯誤:

Argument type {path: string, component HomeComponent}[] is not assignable to parameter type Routes 

不知道是怎麼回事就在這裏,因爲我下面的文檔幾乎到了一封信:https://angular.io/docs/ts/latest/guide/router.html

編輯:home.component.ts

<p>Home works!</p> 
+0

請出示代碼'home.component.ts' –

+1

請從'home.component.ts'添加所有的代碼。 'HomeComponent'應該是一個具有'@ Component'裝飾器的類 – yurzui

回答

0

可以解決這個問題,通過改變你的HomeComponent一點點。 它應該從@angular/core延伸Type。並且不要忘記super方法!

類似的東西:

import { Component, Type } from '@angular/core'; 

@Component({...}) 
export class HomeComponent extends Type { 
    constructor() { 
    super(); 
    } 
    ... 
} 
相關問題