This is my factory:
.factory(\'userService\',()){
var user = {};
return {
getFirstname : function () {
return user.firstname;
},
setFirstname
You have two options to overcome this problem.
Solution 1st:
Adding a watch in your controller.
.controller('MainCtrl',['userService', function(userService) {
$scope.userName = userService.getFirstName();
$scope.$watch(function() {
return userService.getFirstName();
}, function(newValue) {
$scope.username = newValue;
});
}]);
Solution 2nd:
.controller('MainCtrl',['userService', function(userService) {
$scope.getUsername = function() {
userService.getFirstName();
};
}]);
Now your view should directly call this function.
{{getUsername()}}
Now, according to Angular's doc, whenever the return value from a function call changes, Angular will update the values in the view.