我正在嘗試在Angular 2中玩弄並且得到一個測試應用程序運行,但我遇到了一些問題讓路由工作在最新版本的路由器(3.0.0 alpha-7)。Angular 2兒童路由(v3)'不能讀取'undefined'的屬性'註釋'
main.ts:
import {bootstrap} from '@angular/platform-browser-dynamic';
import {AppComponent} from './app.component';
import {APP_ROUTER_PROVIDERS} from './app.routes';
bootstrap(AppComponent, [APP_ROUTER_PROVIDERS]);
app.component.ts:
import {Component} from '@angular/core';
import {ROUTER_DIRECTIVES} from '@angular/router';
@Component({
selector: 'my-app',
template: `
<router-outlet></router-outlet>
`,
directives: [ROUTER_DIRECTIVES]
})
export class AppComponent { }
app.routes.ts:
import {provideRouter, RouterConfig} from '@angular/router';
import {SigninRoutes} from './signin/signin.routes';
export const AppRoutes: RouterConfig = [
...SigninRoutes
]
export const APP_ROUTER_PROVIDERS = [
provideRouter(AppRoutes)
];
signin.component.ts:
import {Component} from '@angular/core';
import {ROUTER_DIRECTIVES} from '@angular/router';
@Component({
selector: 'signin',
template: `
<a [routerLink]="['/signin']">Sign In</a>
<a [routerLink]="['/profile']">Profile</a>
<br><br>Sign In Test
<router-outlet></router-outlet>
`,
directives: [ROUTER_DIRECTIVES]
})
export class SigninComponent {
}
個
signin.routes.ts:
import {Component} from '@angular/core';
import {ROUTER_DIRECTIVES} from '@angular/router';
@Component({
selector: 'signin',
template: `
<a [routerLink]="['/signin']">Sign In</a>
<a [routerLink]="['/profile']">Profile</a>
<br><br>Sign In Test
<router-outlet></router-outlet>
`,
directives: [ROUTER_DIRECTIVES]
})
export class SigninComponent {
}
profile.component.ts:
import {Component} from '@angular/core';
@Component ({
selector: 'profile',
template: `
Profile Test
`
})
export class ProfileComponent {
}
出於某種原因,我可以啓動應用還好,但試圖單擊錯誤配置文件routerLink結果:
「EXCEPTION:錯誤:未捕獲的(在承諾):類型錯誤:無法讀取的未定義的屬性‘註解’」
如果有人可以幫助我的Wi這是非常感謝的。
你的路線是怎樣的? –
請顯示您的路線我有同樣的錯誤:P – Elisabeth