2016-07-08 4 views
0

ルート角度RC4からデータを復旧します: はどうすればアプリのルートで

{ path: 'calculator', component: CalculatorComponent, data: {physical: Physical}},

設定comoponentに:

if(this.selectedPhysical) { 
 
    this.router.navigate(['/calculator', this.selectedPhysical ]); 
 
}

ナビゲーションの結果をしようとしていますこれを行うには(明らかに間違っている):

http://localhost:3000/calculator;pK_Physical=4;fK_Measurement=2;dateString=5/22/2016;weight=270;height=70;hips=27;waist=51;neck=18.5

それでは、どのように私は、ルートにデータを渡すのですか?

電卓コンポーネントでは、次のようなことがあります。どのように渡されたルートデータを取得するのですか?

ngOnInit() { 
 
    this.route 
 
     .data 
 
     .subscribe(v => this.selectedPhysical = <Physical>v); 
 
      
 
    console.log("phys = " + this.selectedPhysical); 
 
}

誰もがこれを行う方法を知っていますか?

+0

に更新されたデータに依存したコードを移動する必要があります。あなたの質問のほとんどは、全く役に立たない明るい色のボタンで構成されています。代わりに '{}'ボタンを使います。 –

+0

共有サービスを使用してコンポーネント間で通信するだけです。データは現在、ルートに静的に追加されたデータだけです。ルータが提供するその他すべてのものは、URL –

+0

に反映されています。このサイトを使用し始めたのは、angular2を取得するための唯一の場所です。 }ボタンをクリックして、投稿をやり直してもらえますか?あなたがルーティングで間違っていることを教えてくれますか? –

答えて

1

あなたが実行可能でないコードのスニペット機能を使用していないならばそれは素晴らしいことだsubscribe(...)コールバック

ngOnInit() { 

    ** problem is here **, I've tried every combination of things and nothing works. Its always undefine. 

    this.route 
     .data 
     .subscribe(v => { 
      this.selectedPhysical = <Physical>v; 
      console.log("phys = " + this.selectedPhysical); 
     }); 

    // don't know about these   
    this.selectedSex = this.userSettings.sex; 

    //console.log('route id =' + this.route.snapshot.params.id) 
} 
+0

私はあなたが提案したことをやったことがあり、それを使用するとまだ未定義です。その他の提案はありますか?ありがとうございました。 –

+0

未定義とは何ですか? –

+0

this.selectedPhysical。 –

関連する問題