DownloadController.js

angular.module('homepage').
controller('DownloadController', function ($anchorScroll, $scope, $state, DataStoreSrvc, DownloadFile, Server) {
    $anchorScroll();

	var inputs = DataStoreSrvc.getInputData();

	$scope.selectedFileType = 'DOCX';

	$scope.selectFileType = function (type) {
		$scope.selectedFileType = type;
	};

    $scope.onBack = function () {
        $state.transitionTo('inputextras');
    };

	$scope.onEdit = function () {
		$state.transitionTo('inputbasic');
	};

	$scope.downloadCV = function () {
        var data = { 'type': $scope.selectedFileType, 'inputs': inputs };
        var callback = null;
		if($scope.selectedFileType === 'RTF') {
            Server.downloadRtf(data).then(function (result) {
                DownloadFile.getPlainText('file.rtf', result.data.content);
            });
        }
        else {
            Server.downloadDocx(data).then(function (result) {
                var fullname = inputs.profile.fullname ? inputs.profile.fullname : 'file';
                DownloadFile.getDocxFile(fullname + '.docx', result.data);
            });
        }

	};

    $scope.print = function () {
        $state.transitionTo('print');
    };

});