We are building what will become a big angular application. We already use heavily directives, services and have as many as 14 controllers.
Our problem is to share data between controllers. We would like to be able to share data between controllers that are far away (not siblings) and that would not break the bi-directional binding.
I proposed to use services dedicated to carrying data.
var MyApp = angular.module('MyApp', []);
MyApp.factory('dataContainer', function(){ return {} });
function FirstCtrl($scope, dataContainer) {
$scope.data = dataContainer;
}
function SecondCtrl($scope, dataContainer) {
$scope.data = dataContainer;
}
You can try it in the fiddle http://jsfiddle.net/didier_/R2Bgs/2/.
Is that good practice?