Javascript 如何在AngularJS中下载和显示文本和png文件?

Javascript 如何在AngularJS中下载和显示文本和png文件?,javascript,angularjs,http,angular-ui,Javascript,Angularjs,Http,Angular Ui,我在服务器上存储了文本和图像文件,需要下载这些文件并将其显示在html网页中。我正在使用AngularJS呈现页面。如果我使用下面的代码获取文件,那么我会得到一个http 200状态响应,但该文件不在正文或响应中的任何其他位置。如果我在FireFox浏览器中输入完全相同的URI,我会得到标准提示,将文件保存到本地,这样我就知道URI是有效的 我如何在AngularJS中获得它?当我得到它时,如何显示它们 app.controller('MainController', function($sco

我在服务器上存储了文本和图像文件,需要下载这些文件并将其显示在html网页中。我正在使用AngularJS呈现页面。如果我使用下面的代码获取文件,那么我会得到一个http 200状态响应,但该文件不在正文或响应中的任何其他位置。如果我在FireFox浏览器中输入完全相同的URI,我会得到标准提示,将文件保存到本地,这样我就知道URI是有效的

我如何在AngularJS中获得它?当我得到它时,如何显示它们

app.controller('MainController', function($scope, dataService) {
    $scope.data = null;
    dataService.getData().then(function(dataResponse) {
        $scope.data = dataResponse;
    });
});

app.service('downloadService', function($http) {
    delete $http.defaults.headers.common['X-Requested-With'];
    this.getData = function() {
        console.log("getting data");
        return $http({
            method: 'GET',
            url: 'https://someAddress.com/pathtofile.txt?securitykey=fakeKey',
            params: '',
            headers: {}
        });
    }
});
--更新--

根据下面的评论,我将代码更新为以下内容,但我只看到图像的图标占位符,而不是图像本身

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

app.controller("MainController", function($scope){
    $scope.path_to_image = "https://someAddress.com/pathtofile.png?securitykey=fakeKey"
});

<div id='content' ng-app='MyTutorialApp' ng-controller="MainController">
    <img ng-src="path_to_image">
</div>
var-app=angular.module('MyTutorialApp',[]);
应用控制器(“主控制器”,功能($scope){
$scope.path_到_图像=”https://someAddress.com/pathtofile.png?securitykey=fakeKey"
});

对于图像文件,无需编写http处理程序

您可以显示图像-

controller.js

$scope.path_to_image = "https://someAddress.com/pathtofile.png"
html

<img ng-src="path_to_image">


谢谢你。获取文件的请求是通过Atmos ObjectStore进行的,因此我需要将安全密钥作为http参数包括在内。很抱歉造成混淆。答案仍然有效,为什么您需要使用http处理程序,如果我没有错,它有有效的密钥,那么它将正确获取图像?如果是唯一的更改,$scope.path_to_image=”“我尝试了您的建议,但我只看到图标图像占位符,而不是实际图像。我已经根据你的建议,用我写的内容更新了原来的问题。我解决了这个问题。在作用域变量周围需要{}括号。Onsy,如果您将建议的解决方案更新为“”,我将接受它。