AngularJS service file upload

A simple service to upload a file from a given input element on demand in your controller.

HTML

<div ng-controller = "myCtrl">
    <a download="content.txt" ng-href="{{ url }}">download</a>
</div>

JavaScript

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

myApp.controller('myCtrl', ['$scope', function($scope){   
    var content = 'file content for example';
    var blob = new Blob([ content ], { type : 'text/plain' });
    $scope.url = (window.URL || window.webkitURL).createObjectURL( blob );
    
}]);