The object returned from pref factory,
{ setPreference: setPreference, currency: pref.currency, name: pref.name, formatTime: formatTime }
assigns currency and name undefined properties. Since undefined not a reference type, currency and name will not βseeβ any updates to the pref object.
I suggest instead that the property that references the pref object be part of the object returned by the factory:
{ setPreference: setPreference, prefs: pref, formatTime: formatTime }
Now, any updates we make to pref will be reflected in prefs . Refer to the properties of this object, as indicated in your controller:
console.log(prefService.prefs.name)
To not change the link that pref points to, use angular.copy() to change the object that pref refers to:
function setPreference(values){
Refresh : to automatically update the view when name changes, I suggest keeping the link to prefs as a property of the scope:
$scope.prefs = prefService.prefs;
Then use {{prefs.name}} in the / HTML view:
<p>Hello {{prefs.name}}!</p>
Updated plunker
source share