Sharing values between controllers

As this is my first venure into the blogging world i thought i would ease myself in.

For my first angular app I decided upon the folder structure of having sub-components within singular components:

-- ParentComponent
-- Controllers
-- Services
-- Directives
-- Components
    -- ChildComponent1
        -- Controllers
        -- Services
        -- Directives

Which is working nicely as adding the child component as a dependency then gives me access to the child controller.

angular.module('parentApp', ['childApp'])

but one issue that I have come across is sharing data from the parent to the child controllers.

I got round this by having a service this is available to both controllers.

angular.module('parentApp')
.service('sharedService', function(){
    var someVariable = {};
});

In the service there is a variable that i would like to give the child controller access to and an array for the callback function (it is an array as then more than one controller could have access to this variable).

Now to add the callback and how to execute the callback.

angular.module('parentApp')
.service('sharedService', function(){
    ...
    return{
        getVariable: function(){
            return someVariable;
        },
        setVariable: function(i){
            someVariable = i;
        }
    }
}

We now have access to set the variable and to return it. This can be used by first setting the variable:

angular.module('parentApp')
.controler('parentController, ['sharedService', function(sharedService){
    sharedService.setVariable('test');
}]);

angular.module('childApp')
.controller('childController, ['sharedService', function(sharedService){
    $scope.variable = sharedService.getVariable();
}]);

This could be extended multiple ways by either having a callback function added to the service or by having a $watch set against the variable.