Q:

Pass data from child state to parent state when leaving child state

I've searched the web for ways to solve this problem and couldn't find best solution. Different approaches were involving using data on states, custom services or parent $scopes, but nothing seems to fit here.
I have parent controller with some object or variable and from this state I can go to child state in which I want to update the variable in parent and go back to parent. The code will explain it better.
function parentController($state) {
    var vm = this;
    vm.myVal = 1;
}

function childController($state) {
    var vm = this;

    vm.changeValue = function () {
        //TODO: change value of myVal in parent so it updates on view
        //if possible allow also updating or passing whole objects to parent
        return $state.go('parent');

        //is it possible to pass anything to reloaded state?
        //return $state.go('parent', {}, {reload:true})
    }
}

Full working code is available here on Plunker. 
I'm quite new to AngularJS so it's possible I get something fundamentally wrong and code needs reworking to allow this. I would rather stay with controller as syntax though.
What is the best way to approach this? Please fork the Plunker with working solution if you can. 

A:

This is an example of communication between 'parent/child' controllers by using the hierarchical behaviour of Angular's $scope. ($scope is special in angular!)
function parentController($scope) {
  var self = this;

  this.myVal = 1;
  this.myMessage = "Starting message";

  // set up method that child controllers can call.
  $scope.signalParent = function(data) {
    console.log("Parent signalled with " + JSON.stringify(data));
      self.myVal++;
      self.myMessage = data.msg;
      if (!$scope.$$phase) {
          $scope.$apply();
      }
  };
}

function childController($scope) {
  var self = this;
  this.changeValue = function() {
     // call the method from the parent.
    $scope.signalParent({msg: "Hello " + Math.random(100)});
  };
}
})();

Plunkr: plnkr.co/edit/1yhFAcGq7nUS37VtpAlr?p=preview
The parent controller sets the $scope's "signalParent" property to be a function. Any lower level controller will 'inherit' the $scope and can therefore call the signalParent() method.
I must say that it is considered incorrect to communicate "directly between controllers" AFAIK. "event handling" & "signalling" is preferred.

