0

I want to take input values from user like name, address, phone. After entering values I want to generate a doc (ms word doc file), make it available to be downloaded locally on button click using angularjs. How can I achieve this?

Is it possible at client side or it should be from server side?

<input type='text' ng-model='user.username'/>
<input type='number' ng-model='user.phone'/>
<a href='someX.doc' download>download</a>

in my controller, I want to generate doc file, download it on click of link (download).

2

1 Answer 1

0

This will work

In your HTML add the following Line

    <a download='someX.doc' ng-click="downloadMyDoc()" ng-href="{{ url }}" style="cursor: pointer">Download</a>

In your angular file add the following var app=angular.module("myApp",[]);

    app.config(['$compileProvider',
    function ($compileProvider) {
        $compileProvider.aHrefSanitizationWhitelist(/^\s*(https?|ftp|mailto|tel|file|blob):/);
    }]);

    app.controller("homeCtrl",function($scope){

        $scope.user={};
        $scope.downloadMyDoc=function(){
            alert("a");
            var user=$scope.user;

            var content = 'Username: '+user.username+'phone: '+user.phone;
            var blob = new Blob([ content ], { type : 'text/plain' });
            $scope.url = (window.URL || window.webkitURL).createObjectURL( blob );

        }       
    });
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.