我試圖建立路由首次上角4:Angular4:無法編譯:參數類型{路徑:串,組分HomeComponent} []是不能分配給參數類型路由
我app.module.ts代碼:
import { BrowserModule } from '@angular/platform-browser';
import { NgModule } from '@angular/core';
import { RouterModule } from '@angular/router';
import { AppComponent } from './app.component';
import { ProductComponent } from './product/product.component';
import { MembersComponent } from './members/members.component';
@NgModule({
declarations: [
AppComponent,
ProductComponent,
MembersComponent
],
imports: [
BrowserModule,
NgModule,
RouterModule.forRoot([
{
path: 'member',
component: 'MembersComponent'
},
{
path: 'product',
component: 'ProductComponent'
}
])
],
providers: [],
bootstrap: [AppComponent]
})
export class AppModule { }
我得到的錯誤:
Argument of type '{ path: string; component: string; }[]' is not assignable to parameter of type 'Route[]'. Type '{ path: string; component: string; }' is not assignable to type 'Route'. Types of property 'component' are incompatible. Type 'string' is not assignable to type 'Type'.
請刪除 '' 行情只是添加MembersComponent在組件屬性 –
組件用作字符串,但它應該是一種組件。你必須記住你正在使用打字稿,它理解類型。 –