I. The answer to question:
... child since its not nested ... Is there a way to get that metricdata property in the child?
Is based on
Child states DO inherit the following from parent states:
- Resolved dependencies via resolve
- Custom data properties
Nothing else is inherited (no controllers, templates, url, etc).
in conjuction with
Keep in mind that scope properties only inherit down the state chain if the views of your states are nested. Inheritance of scope properties has nothing to do with the nesting of your states and everything to do with the nesting of your views (templates).
It is entirely possible that you have nested states whose templates populate ui-views at various non-nested locations within your site. In this scenario you cannot expect to access the scope variables of parent state views within the views of children states.
II. While this should be clear now, we still need to find a way how to solve:
... Is there a way to get that metricdata property in the child without having to manually call the same ajax call again in the child..
And I would say, there is also answer. E.g.
.. move the shared views/resolvers to the least common denominator. ..
E.g. we can do it like in this Q & A: Controlling order of operations with services and controllers, see the plunker:
A special grand parent / root state:
$stateProvider
.state('root', {
abstract : true,
// see controller def below
controller : 'RootCtrl',
// this is template, discussed below - very important
template: '<div ui-view></div>',
// resolve used only once, but for available for all child states
resolve: {
user: function (authService) {
return authService.getUserDetails();
}
}
})
Passing resolved stuff into $scope (inherited by each child)
.controller('RootCtrl', function($scope,user){
$scope.user = user;
})
This is injected on top of our state / view hierarchy, and any child state would profit from it
// any previously root state will just use the above as a parent
.state('index', {
url: '/',
parent : 'root',
Check more details here and see it in a working example