angularjs-http

Retrieving data out of post success from separate controller angularjs

南笙酒味 提交于 2019-12-02 17:28:16
问题 I am writing a simple service that uploads a file and posts it to a Spring controller. The controller manipulates this data and returns several objects as JSON. I am working with the following Angular service: myApp.service('fileUpload', [ '$http', function($http) { this.uploadFileToUrl = function(file, uploadUrl) { var fd = new FormData(); fd.append('file', file); $http.post(uploadUrl, fd, { transformRequest : angular.identity, headers : { 'Content-Type' : undefined } }) .success(function

returning image/jpeg as arraybuffer or blob

五迷三道 提交于 2019-12-02 11:49:38
I am currently making a call to my api which returns an image as an image/jpeg . My issue is the when calling the url through javascript angular .factory resource I am getting my array buffer as empty {} . Also, the bytes length is 0. If I make the call to the api url with response type '' or 'text' I do see value of multiple types. What am I missing here? Thank you for your help! JS: .factory("Img", function($resource) { return $resource("http://mypathTo/image/:id", { id: "@id" }, { responseType: '' //arraybuffer return empty }); }); app.controller //code $scope.getImage = function(productid)

How to download a zip file in AngularJS / FilesaverJS [duplicate]

浪子不回头ぞ 提交于 2019-12-02 10:28:56
This question already has an answer here: Binary files corrupted - How to Download Binary Files with AngularJS 2 answers i have a service function which return me 3 result files(2 text files, 1 zip file). i want to check the header of the response to see if the file is a zip or a text to set the right configuration to download the file. my controller resolved the promise from my service. if i download a text file -> the file says [object object] .. i have seen in my browser that the response body is from content-type: text/plain i am bit confused :/ controller : $scope.getResult = function(rid

Retrieving data out of post success from separate controller angularjs

☆樱花仙子☆ 提交于 2019-12-02 10:21:42
I am writing a simple service that uploads a file and posts it to a Spring controller. The controller manipulates this data and returns several objects as JSON. I am working with the following Angular service: myApp.service('fileUpload', [ '$http', function($http) { this.uploadFileToUrl = function(file, uploadUrl) { var fd = new FormData(); fd.append('file', file); $http.post(uploadUrl, fd, { transformRequest : angular.identity, headers : { 'Content-Type' : undefined } }) .success(function(data) { console.log("upload successful") //console.log(data) namesandaddresses = data; }) .error(function

Getting the response as “data”:null,“status”:-1 when calling web api from AngularJS

对着背影说爱祢 提交于 2019-12-02 09:28:37
I am trying to call Web API GET Method from Angular JS 1.6.0 and getting the following error:- Possibly unhandled rejection: {"data":null,"status":-1,"config":{"method":"GET","transformRequest":[null],"transformResponse":[null],"jsonpCallbackParam":"callback","url":" http://localhost:51972/api/video ","headers":{"Accept":"application/json, text/plain, / "}},"statusText":""} I am getting the proper JSON response when I call the same GET method from Fiddler 4 and returning JSON Text. Please note that my WEB API and Angular JS code are in different directory. As per Dez's comment I have modified

Replacing $http with Fetch API

给你一囗甜甜゛ 提交于 2019-12-01 20:16:21
问题 I'm replacing $http with Fetch API and got replaced $q with Promise API. Because of that, Angular didn't run digest cycles anymore, thus UI didn't render. To solve this problem I tried Zone.js and that seems to solve our problems partially. Unfortunately its API completely changed in 0.6 so we're using legacy 0.5.15. Now to the actual problem. When refreshing the page Angular configs and bootstraps the application like expected. In this phase I'm initializing the Zone and decorating the

Replacing $http with Fetch API

╄→гoц情女王★ 提交于 2019-12-01 18:40:07
I'm replacing $http with Fetch API and got replaced $q with Promise API. Because of that, Angular didn't run digest cycles anymore, thus UI didn't render. To solve this problem I tried Zone.js and that seems to solve our problems partially. Unfortunately its API completely changed in 0.6 so we're using legacy 0.5.15 . Now to the actual problem. When refreshing the page Angular configs and bootstraps the application like expected. In this phase I'm initializing the Zone and decorating the $rootScope.apply with the Zone and $rootScope.$digest() . Now when I transition between states/routes (with

Testing backend API via $http in AngularJS/karma/jasmine tests?

依然范特西╮ 提交于 2019-12-01 03:43:55
How do I test my API backend using AngularJS/karma/jasmine tests? I have tried to create the smallest test-case showing my error: echo_server.py from bottle import response, route, run @route('/echo/<echo>') def echo_echo(echo): response.headers['Access-Control-Allow-Origin'] = '*' return {'echo': echo} # Served as JSON if __name__ == '__main__': run() test/unit/apiSpec.js // Should this be in `test/e2e/apiSpec.js`? describe('echo', function () { var scope, http; beforeEach(inject(function ($rootScope, $http) { $http.defaults.useXDomain = true; // CORS scope = $rootScope.$new(); http = $http;

Testing backend API via $http in AngularJS/karma/jasmine tests?

末鹿安然 提交于 2019-12-01 01:00:40
问题 How do I test my API backend using AngularJS/karma/jasmine tests? I have tried to create the smallest test-case showing my error: echo_server.py from bottle import response, route, run @route('/echo/<echo>') def echo_echo(echo): response.headers['Access-Control-Allow-Origin'] = '*' return {'echo': echo} # Served as JSON if __name__ == '__main__': run() test/unit/apiSpec.js // Should this be in `test/e2e/apiSpec.js`? describe('echo', function () { var scope, http; beforeEach(inject(function (

$http issue - Values can't be returned before a promise is resolved in md-autocomplete Angular Material

心不动则不痛 提交于 2019-11-30 15:58:38
I'm using Angular Material md-autocomplete in my project. In that I'm getting the suggest listing from the Service Host via ajax call using $http service. Issue : $http issue - Values can't be returned before a promise is resolved in md-autocomplete Angular Material My Requirement : I need an updated Suggestion List using remote data sources in md-autocomplete Angular Material - Ajax $http service. I used the approach as mentioned in Angular Material link https://material.angularjs.org/latest/demo/autocomplete Source Code: Scenario 1: HTML Source Code: <md-autocomplete flex required md-input