我想下载本地计算机中的文件。每当我点击下载链接时,它都会在浏览器中提供不安全的URL:http://localhost:8080/MYOB_Fabric/%7B%7B
HTML code:
<div ng-controller="MainCtrl">
<table class="table2" border=1 frame=void rules=rows>
<tr>
<th colspan=3>Transaction Details</th>
</tr>
<tr>
<th>Hash</th>
</tr>
<tr ng-repeat="transaction in transactionDetails ">
<td><a ng-href={{ fileUrl }} download="logFile.txt">{{ transaction.Hash }}</a></td>
</tr>
</table>
</div>
Js代码:
var appHlVl = angular.module('hlfabric', [ 'ngRoute' ]);
appHlVl.config(['$compileProvider', function($compileProvider) {
$compileProvider.aHrefSanitizationWhitelist(/^\s*(|blob|):/);
}]);
appHlVl.controller('MainCtrl', function($scope, $rootScope,$http,$window,$sce) {
var txtfileURL = '/home/rajasekhar/peer-log.txt';
$http.get(txtfileURL, { responseType: 'arraybuffer' })
.then(function success(response) {
var file = new Blob([response.data], {
type: 'text/plain'
}),
url = $window.URL || $window.webkitURL;
$scope.fileUrl = $sce.trustAsResourceUrl(url.createObjectURL(file));
});
});
答案 0 :(得分:0)
<a ng-href="{{fileUrl}}" target="_blank">{{ transaction.Hash }}</a>
或app.config文件放入此行
$compileProvider.aHrefSanitizationWhitelist(/^\s*(https?|ftp|mailto|chrome-extension):/);
答案 1 :(得分:0)
试试这个
app.config(['$compileProvider', function($compileProvider) {
$compileProvider.aHrefSanitizationWhitelist(/^\s*(https?|file|tel):/);
}]);