Q:

Javascript Blob() does not create file in first click

<a href="" 
   ng-click="$ctrl.downLoadFile(file)" 
   ng-attr-id="{{file.id}}">{{file.filename}}</a>

A click on the above <a> tag gets a file.csv from the server. Inside the success method, I create the file. But the problem is that it does not download it with the first click. In the first time, I have to click two times to download the file. After the second click, It works as expected.
How to solve this issue? I want it to work with the the first click also.
Here is the code. 

    downloadService.getFile(file).then(
        function success(response) {
            var data = response.data,
            filename = file.filename.split("/"),
            name = (filename[filename.length - 1]),
            blob = new Blob([data], {type: 'application/octet-strea'}),
            url = $window.URL || $window.webkitURL,
            fileUrl = url.createObjectURL(blob);
            var anchor = angular.element(document.getElementById(
                         file.id.toString()));
            anchor.attr({
                href: fileUrl,
                target: '_blank',
                download: name
            })
            }
        );

This is the <a> tag that I access in 
Appreciate all kinds of solutions and tips. Thanks in advance! 

A:

Solved this problem with creating a new <a> tag. 

function success(response) {
          var data = response.data,
            blob = new Blob([data], {type: 'application/octet-stream; charset=UTF-8'}),
            url = $window.URL || $window.webkitURL,
            fileUrl = url.createObjectURL(blob);

          var anchor = document.createElement('a');

          anchor.href = fileUrl;
          anchor.target = '_blank';
          anchor.download = name;
          anchor.style = "display: none";

          document.body.appendChild(anchor);
          anchor.click();

          setTimeout(function () {
            document.body.removeChild(anchor);
            $window.URL.revokeObjectURL(fileUrl);
          }, 100);
        }

