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 = '',
        _setUsername = function (username) {
            _username = username;
        },
        _sayHello = function () {
            return 'Hello, ' + _username;
        };
    
    return {
        setUsername: _setUsername,
        sayHello: _sayHello
    };
    
});
<div ng-app="APP" ng-controller="APP.ApplicationCtrl">
    <h1>{{ getHelloMessage() }}</h1>
</div>