I have a service called SharedData which is defined like this:
appServices.service('SharedData', function() {
var data = {};
function setContacts(contacts) {
data.contacts = contacts;
};
function getContacts() {
return data.contacts;
};
return {
setContacts: setContacts,
getContacts: getContacts
};
});
In one of my controllers, I retrieve the data using the following code:
$scope.contacts = SharedData.getContacts();
While this works fine, I would like for $scope.contacts
to be notified and update its data whenever there are changes in the SharedData.
How can I achieve this functionality?