angular-http

res.json() is a not a function in HttpClient Angular 2

倾然丶 夕夏残阳落幕 提交于 2019-12-01 06:11:28
问题 I was using Angular Http module before and the method res.json() used to work fine. I have recently tried HttpClient but then the res.json() dosen't seem to work . only using res works can some one tell me what changed has happened in the http client. return this.client.get('https://swapi.co/api/people/1/') .map((res:Response) => { return res.json(); // using maps to filter data returned form the http call this json dosn't work with http client }).map(data => { return data; // using maps of

Non blocking Ajax request to PHP

前提是你 提交于 2019-12-01 05:34:57
问题 I'm using PHP to download a (big) file from a remote server and this download is triggered by clicking on a download button on a web page. So when i click the download button on the web page, then an Ajax request (with angulars $http ) is made to a PHP function. That function triggers a download using cURL . In the mean time I'd like to make other requests to my PHP site with Ajax. But all other Ajax requests show the status Pending as long as the download is in progress. So basically the

Angular 6 HttpClient return instance of class

断了今生、忘了曾经 提交于 2019-12-01 04:09:09
Before angular's new HttpClient was introduced, our objects returned from the http api call could be validated with the instanceof keyword. they no longer can with the HttpClient Module. I'm trying some simple methods but the type checks return false every time. the desired behavior of: ``` getCow() { return this.http.get<Cow>(ApiRoute.GET_COW, options) .map(res => res as Cow) .toPromise() .then((c: Cow) => { console.log(c instanceof Cow); //this is false }) } ``` would return true. does anyone know of a simple way to new up an instance behind the scenes of the http client? TypeScript uses

JsonP returning “Uncaught SyntaxError: Unexpected token :” AngularJS - routingnumbers.info

前提是你 提交于 2019-11-30 21:53:09
问题 I've researched this question a ridiculous amount and would hope that someone can help diagnose what is wrong. I've already tried looked at the following SO questions: (SO wouldn't let me post more than 2 links due to reputation, so i've just included the paths) questions/16344933/angularjs-jsonp-not-working/16352746#16352746 questions/19269153/jsonp-request-in-angularjs-doesnt-work-like-in-jquery questions/19669044/angularjs-getting-syntax-error-in-returned-json-from-http-jsonp Among many

How to prioritize requests in angular $http service?

走远了吗. 提交于 2019-11-30 15:48:16
I'm working on an application with a large amount of lazy data loading. I would like to prioritize http requests based on 'priority' param. This is the concept of using it. $http.get(url, {params: query, priority: 1}) I was thinking of using $http interceptors. Something like that: angular.module('myModule') .factory('httpPriorityInterceptor', function ($interval, $q) { var requestStack = []; return { request: function (config) { config.priority = config.priority || 3; requestStack.push(config); requestStack.sort(sortByPriority); if (isFirstToGo(item)) return requestStack.pop(); deferred = $q

Angular 2 http request with Access-Control-Allow-Origin set to *

北慕城南 提交于 2019-11-30 07:56:47
问题 I'm using angular2 and typescript. I'm trying to post to my mail chimp subscription list. My code so far: constructor(router: Router, http: Http){ this.router = router; this.http = http; this.headers = new Headers(); this.headers.append('Content-Type', 'application/json'); this.headers.append('Access-Control-Allow-Origin', '*'); } subscribe = () => { var url = "https://thepoolcover.us10.list-manage.com/subscribe/post?u=b0c935d6f51c1f7aaf1edd8ff&id=9d740459d3&subscribe=Subscribe&EMAIL=" + this

Getting data from a web service with Angular.js

爷,独闯天下 提交于 2019-11-30 04:05:28
Im trying to get data in a Json format from a remote WS using Angular and im having some trouble. The data comes from the web service correctly but i cant use it inside the controller. Why is that? Angular Code: var booksJson; var app = angular.module('booksInventoryApp',[]); // get data from the WS app.run(function ($http) { $http.get("https://SOME_API_PATH").success(function (data) { booksJson = data; console.log(data); //Working }); }); app.controller('booksCtrl', function ($scope) { $scope.data = booksJson; console.log($scope.data); //NOT WORKING }); HTML: <section ng-controller="booksCtrl

Getting JSON for Angular 2 from HTTP remote server fails, but succeeds localy

人走茶凉 提交于 2019-11-29 16:40:49
I'm trying to read a JSON file using htttp.get in Angular2. When I use a file stored localy on my project, it works OK . But - when I use a remote server , with exactly the same file, I get the following error: 404 - Not Found Collection 'undefined' not found Browsing to http://example.com/my.json , I can see the file on any browser. Here is my typescript code for getting the file: private url = '../my.json'; <--- This works private url = 'http://example.com/my.json'; <--- This throws the error return this.http.get(this.url) .map(this.extractData) .catch(this.handleError); Thanks in advance.

Angular HttpClient params with method GET do not work

六眼飞鱼酱① 提交于 2019-11-29 15:46:31
I wanna ask you about params with get method. I have something like this: path = 'https://example.com/api'; const params = new HttpParams(); params.append('http', 'angular'); return this.http.get(path, {params: params}); I thought I would have url like: www.example.com/api?http=angular but actually when I check that in network tab in chrome, request url is www.example.com/api What should I do when I want to have path: www.example.com/api?http=angular And is it possible to check request url of used method without chrome? I mean in service where I use that method? You need to reassign after the

Angular sending token with get (and other) requests

旧城冷巷雨未停 提交于 2019-11-29 14:40:54
问题 For some reason, the internet is devoid of examples on how to do this in Angular 4 (which uses TypeScript, which doesn't let you skip including option properties like the JavaScript it transpiles into does). I'm trying to hit my team's RESTful API, which requires an authentication token, with GET request, like, for example : return this.http.get(this.BASE_URL + '/api/posts/unseen/all', { headers : { "Authorization": 'Token token="' + TokenService.getToken() + '"' } }) where TokenService is