domokun domokun - 1 year ago 96
Javascript Question

Is there a way to pass variables to a controller from ui.router?

I have a page structured with some nested views, using

and I would like to pass some data from the parent controller to the child controller, without injecting useless services into the child controller.

In my mind, something like these would be perfect

state('home', {
url: "/home",
templateUrl: "parts/home.html",
controller: "FatherController"
state('home.child', {
url: "/child",
templateUrl: "parts/home/child.html",
controller: "ChildController",
params: {$ = $rootScope.someData}

Do you happen to know if there is a way to do this?

Answer Source

If your child view is nested within the parent view, your child controller will automatically inherit the parent scope.

You should be able to access the parent controller's data directly from the child controller.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download