If you have data, you can use the value. Add a value to each of your controllers and save it in your area, and then specify the value property in your template. If you use the Service, you can do almost the same thing. My example shows one solution using each.
See this example:
http://plnkr.co/edit/qTbSjnf6Q2FVDurGZhKd
<div ng-controller="MainCtrl">
<input ng-model="mainVal.value"></input>
<input ng-model="mainSvcVal.value"></input>
</div>
<div ng-controller="OtherCtrl">
<input ng-model="otherVal.value"></input>
<input ng-model="otherSvcVal.value"></input>
</div>
var app = angular.module('plunker', []);
app.value('MyValue', {value: "Hello There"});
app.service('MyService', function() {
this.myData = {
value: "Goodbye"
}
});
app.controller('MainCtrl', function($scope, MyValue, MyService) {
$scope.mainVal = MyValue;
$scope.mainSvcVal = MyService.myData;
});
app.controller('OtherCtrl', function($scope, MyValue, MyService) {
$scope.otherVal = MyValue;
$scope.otherSvcVal = MyService.myData;
});
It should be noted that if you reassign MyService.myData to a new object, this will break the connection.
source
share