0

Issue Simulation: http://plnkr.co/edit/ZPgMxGwhha7S1cmTSNg8?p=info

Description: I want to share the data of parent state to child state. I am not creating a separate controller for child states. Also I am creating a nested views. So ideally children should share the parent scope. But it is not working.

this.successHandler = function(data){
   console.log("Inside Success Handler");
   mainCtrl.company = data;
};

I am initializing the company object in parent scope and binding it with the view of child state.

<input class="form-control" ng-model="mainCtr.company.name" type="text" placeholder="Enter Name Here">

I have checked one of the approach here. But somehow it is not working in my case. Also I am trying to avoid usage of $scope and using "this" instead. Can someone help me accessing "mainCtrl.company" data inside all the three tabs?

Community
  • 1
  • 1
Mahesh
  • 1,427
  • 2
  • 19
  • 42

2 Answers2

0

You seem to be doing it correctly, except having mispelt mainCtrl as mainCtr in your child views.

xiankai
  • 2,773
  • 3
  • 25
  • 31
0

In short, angular's child scope inherits from its parent scope, which is available in view without the $scope prefix. Because you use this instead of $scope to manage your data and fields, you need to create a communicate property (what controllerAs do here) . If there is no 'controllerAs', let's say we want a parent property, (add $scope.parent = this; in mainController L:29), and access with parent.company.name in the 3 child states with

<input class="form-control" ng-model="parent.company.name" type="text" placeholder="Enter Name Here">
maow
  • 1,387
  • 11
  • 20