4

with ui-router, any child and grandchild of a state has access to their parent and grandparents controller correct?

So for example a .state(resources.resource.rates) the .rate state controller has access to the $scope.objects in resource and resources (which all have their own controllers) right?

On the presumption I have a html set up where everything is a nested view within resources with a ui-view="content2". However I have another page within resource called rates I would like to open up in the same nested view as resources but also gets access to the resource controller as well.

.state('resources.resource.rates', {
    url: '/rates',
    views:{
        "content2":{
            templateUrl: 'templates/rates.html',
            controller: 'CreateRatesCtrl'
        }
    }   
})  

my ng-href in my view links to the /resources/{{resource.Id}}/rates but doesn't open up the rates page in the resources ui-view.

so what I tried was setting the view to content2@resources like so

views:{
        "content2@resources":{
            templateUrl: 'templates/rates.html',
            controller: 'CreateRatesCtrl'
      }
}   

This works in the sense that the html now populates the rates.html in the resources ui-view and with the ng-href as resources/{{resource.Id}}/rates but unfortunately I only have access to the resources scope objects. I have a resourceId that I need from the resource controller. Does setting content2@resources limit my scope access to only the resources controller in this case? If so how can I make it so I can get access to the resource controller as well?

Garuuk
  • 2,153
  • 6
  • 30
  • 59
  • Your questions it hard to understand. Are you able to possibly create a fiddle showcasing the value you are trying to reach, but can't? – Matt Way Aug 12 '14 at 22:47
  • Here is a example of nested views with ui-router: http://stackoverflow.com/questions/22187231/doubly-nested-views-ui-router-or-ui-bootstrap-tabs-accordion/22189954#22189954 – cheekybastard Aug 13 '14 at 00:29
  • @MattWay Yeah I had trouble articulating the problem sorry >< but Valentin pretty much described how ui-router handles controller inheritance which I'll use to solve my problem, thanks. – Garuuk Aug 13 '14 at 17:07

1 Answers1

5

Quoted from ui-router wiki :

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).

This should be enough to understand what nesting of states and/or views gives and doesn't give you.

Valentin Waeselynck
  • 5,950
  • 26
  • 43