关闭ng-href - 下载文件后交叉按钮或自动关闭

时间:2017-07-26 14:42:17

标签: javascript angularjs

我动态显示带有下载某个文件的链接的消息(确实有效):

<a ng-href = "{{myCtrl.fileUrl}}" download = "{{myCtrl.file}}">
    {{myCtrl.file}}
</a>

如何关闭(甚至更好 - 在右上角添加交叉)此消息?

1 个答案:

答案 0 :(得分:1)

请按照以下步骤操作:

 1. Add ng-hide directive to your anchor tag. Example ng-hide="hideLink"
 2. Call a function on click of download link. Example ng-click="downloadLinkClicked()"
 3. Within the function, set $scope.hideLink = true;
 4. Your download link will be hidden now.

代码段:

在你HTML

<a ng-href = "{{myCtrl.fileUrl}}" download = "{{myCtrl.file}}" ng-hide="hideLink" ng-click="downloadLinkClicked()">
    {{myCtrl.file}}
</a>

js控制器中:

$scope.hideLink = false;
    $scope.downloadLinkClicked = function () {
        $scope.hideLink = true;
    }