angular: Router resolved data does not persist in ActivatedRoute data after navigation

I’m submitting a … (check one with “x”)

[x] bug report => search github for a similar issue or PR before submitting
[ ] feature request
[ ] support request => Please do not submit support request here, instead see https://github.com/angular/angular/blob/master/CONTRIBUTING.md#question

Current behavior The router resolved properties are not persisted inside the ActivatedRoute data unlike the data properties.

Expected behavior The router resolved properties should be persisted inside the ActivatedRoute data like the data properties.

Minimal reproduction of the problem with instructions http://plnkr.co/edit/twhzHaywqxVDPhD2R1NT?p=preview

What is the motivation / use case for changing the behavior? Some motivations are:

  • Preload data application wide
  • Reuse preloaded data

Please tell us about your environment:

  • Angular version: 2.1.0

  • Browser: [all | Chrome XX | Firefox XX | IE XX | Safari XX | Mobile Chrome XX | Android X.X Web Browser | iOS XX Safari | iOS XX UIWebView | iOS XX WKWebView ]

  • Language: [all | TypeScript X.X | ES6/7 | ES5]

  • Node (for AoT issues): node --version = v6.8.0

About this issue

  • Original URL
  • State: closed
  • Created 8 years ago
  • Reactions: 2
  • Comments: 19 (18 by maintainers)

Commits related to this issue

Most upvoted comments

so can you explain why I can access the data defined in the data property of the parent without calling parent.data

it’s the actual bug. and u have access only on initial navigation. or may be it’s a feature. Need feedback from Victor

http://plnkr.co/edit/NgDlGWjrMQC8pMVzSVkA?p=preview this is the correct plunker and expected behavior.

Did he write anything about data availability in his blog? No.

@michaelchiche it is not hack, it is the way you can access data from parents, you can write simply function that go upward to any level. ‘Parent’ is a public property of route and snapshot. I didn’t see any reasons do not use it. More then this it is the right way to get data from parents. How do you think to implement all data at all levels? Let say we have n levels and all levels resolves to data, in first level we have one property of data, next level adds one more, and finally we have n(n+1)/2 properties and n^2 complexity. Of course we can use prototyping but this is the same like parent property.

function getParentData(snapshot:any, level:number) {
  var ref = snapshot;

  while (level--) {
     ref = ref.parent;     
  }
  return ref.data;
}