Edit in JSFiddle

var APP = angular.module('APP', []);

APP.ApplicationCtrl = function ($scope, User) {
    
    User.setUsername('mrzepinski');
    
    $scope.getHelloMessage = function () {
        return User.sayHello();
    };
    
};
                                 
APP.factory('User', function () {
    
    var _username = '';
    
    return {
        setUsername: function (username) {
            _username = username;
        },
        sayHello: function () {
            return 'Hello, ' + _username;
        }
    };
    
});
<div ng-app="APP" ng-controller="APP.ApplicationCtrl">
    <h1>{{ getHelloMessage() }}</h1>
</div>