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 click on button 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).

mplungjan
  • 169,008
  • 28
  • 173
  • 236
Shaik Habeeb
  • 205
  • 1
  • 5
  • 15
  • .doc files are not portable. – Maya Jun 30 '17 at 13:10
  • possible duplicate of [Using JavaScript to “Create” a Microsoft Word Document](https://stackoverflow.com/questions/6779926/using-javascript-to-create-a-microsoft-word-document) – Sampgun Jun 30 '17 at 13:10

1 Answers1

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 );

        }       
    });