こんにちはI成分に角度4は角度経路に複数のparamsを通過4
APP-routing.module.ts
import { NgModule } from '@angular/core';
import { Routes, RouterModule } from '@angular/router';
import { StartGameComponent } from './start-game/start-game.component';
import { GameComponent } from './game/game.component';
const appRoutes: Routes = [
{ path: '', redirectTo: '/first', pathMatch: 'full' },
{ path: 'startGame', component: StartGameComponent },
{path: 'game/:width/:height',component: GameComponent
}
];
@NgModule({
imports: [RouterModule.forRoot(appRoutes)],
exports: [RouterModule]
})
export class AppRoutingModule {
}
にルーティングといくつかのparamsを通過したいStartGameComponent
goToGameComponent(width:string,height:string){
this.router.navigate(['game', {width:width,height:height}]);
}
コンポーネント内GameComponent
0123それはだapp.component.html<div>
<md-toolbar color="primary">
<span>MineSweeper Wix</span>
</md-toolbar>
<router-outlet></router-outlet>
<span class="done">
<button md-fab>
<md-icon>check circle</md-icon>
</button>
</span>
</div>
で
ngOnInit() {
this.route.params.forEach((urlParams) => {
this.width= urlParams['width'];
this.height=urlParams['height'];
});
は
は、任意のルートを照合することはできません、私のエラーがスローされます。 URLセグメント: 'game; width = 10; height = 10'
大きな説明をいただきありがとうございます。私の問題を解決するのに役立ちます。 –
反対側からパラメータを取得する方法は?私はあなたが移動するコンポーネントを意味しますか? – smartmouse
@DeborahK "process 1"のようなスペースを持つ文字列パラメータをどうやって渡すのですか? –