2016-11-10 5 views
1

に基づいて角度2でデータ変更登録:私は、次のルートがあると、ルートナビゲーション

[ 
    { 
     path: 'view', 
     children: [ 
      { 

       path: ':id', 
       component: CustomerViewComponent, 
       resolve: { 
        customerViewData: CustomerResolve, 
        edit: ViewRouteResolve // Returns false 
       }, 
       data: { 
        other: false 
       }, 
       children: [ 
        { 
         path: 'edit', 
         resolve: { 
          edit: EditRouteResolve // Returns true 
         }, 
         data: { 
          other: true 
         } 
        }, 
        { 
         path: '', 
         data: { 
          other: false 
         } 
        } 
       ] 
      } 
     ] 
    }, 
    { path: '', component: CustomerListComponent } 
] 

私は/ビューCustomerViewComponentを利用したい/と/ビュー/ 1 /編集

問題は私のコンポーネントでこのデータ変更をキャッチすることができないことです。私はresolveまたはdataで試してみましたが、私はすべての変更をキャッチすることはできません予想通り...

このコードはトリガされません。

this.route.data.subscribe(m => { 
    debugger; // Triggers only once the view loads, then never again 
}); 

// This triggers quite often, but the data is always stale. 
this.router.events.subscribe(m => { 
    console.log(this.route.snapshot.data['edit']); 
    console.log(this.route.snapshot.data['other']); 
    debugger; 
}); 

が、これはバグだろうか?私の唯一の回避策は、イベントNavigationEndを見てた.url文字列プロパティを分析...

答えて

2

私は答えに感謝@angular/router

this.activatedRoute.params.subscribe(params => { 
    console.log(params['edit']); 
    console.log(params['other']); 
}); 
+0

からActivatedRouteを使用する代わりにしようとすることです。 'this.route'は実際に' ActivatedRoute'ですが、 'params'ではなく' data'を見ています。 – jsgoupil

+1

ああ、そうです。この回答を確認してくださいhttp://stackoverflow.com/a/38652281/3159399 –

+0

うわー、これは醜いデザインです...私はGitHub上のバグをブラウズしており、それらはすべて設計によって閉じます。同じ問題を報告している複数の人がいます...これは設計上の問題です。 – jsgoupil

関連する問題