angular-http

Make parallel calls http get or post calls in angular 2

余生颓废 提交于 2020-04-13 06:07:28
问题 How to make parallel calls HTTP get or post calls in angular 2? I have 2 service calls on the response of one callus have to make another call. Could some suggest me how to call make these parallel calls with error handling scenarios? 回答1: If your service is Observable based instead of Promise you can do forkJoin . It runs all observable sequences in parallel. For RxJS version < 6 import 'rxjs/add/observable/forkJoin'; Make sure to import forkJoin from rxjs library Observable.forkJoin

Angular : Using the equivalent of RequestOptions of Http with HttpClient

一世执手 提交于 2020-01-15 03:24:10
问题 i'm migrating from Http to HttpClient I'm used to add some headers to my http requests like the following with : import { RequestOptions, Request, RequestMethod, Headers } from '@angular/http'; this.pass = btoa(cuid + ': '); this.pass = "Basic " + this.pass; this.header = new Headers(); this.header.set("Authorization", this.pass); let options = new RequestOptions({ headers: this.header }); return this.http.post(myServiceUrl, {}, options) Now when migrating to httpClient , i ve tried this :

Angular http returning status 0, but I expect 404

北城以北 提交于 2020-01-14 09:43:49
问题 I'm making a request to a server that has the following routes: app.use('/401', (req, res) => res.status(401).end()); app.use('/403', (req, res) => res.status(403).end()); app.use('/404', (req, res) => res.status(404).end()); app.use('/500', (req, res) => res.status(500).end()); app.use('/502', (req, res) => res.status(502).end()); app.use('/503', (req, res) => res.status(503).end()); app.use('/504', (req, res) => res.status(504).end()); When I make a request with Angular ( /404 , {} ):

Angular 4 Observable service not working for an api http get

此生再无相见时 提交于 2020-01-14 06:20:14
问题 Angular 4 Observable service not working for an api http get. The http that returns an observable doesnt seem to work. I'm using the new HttpClient This is the error I get: Error: Cannot find a differ supporting object '[object Object]' of type 'object'. NgFor only supports binding to Iterables such as Arrays. Solution? It doesn't seem to like Observable going to the ngFor. Maybe I need to do a switchMap? in the component. This is my http service call: import { Injectable } from "@angular

how to sent array data as formdata angular 4

三世轮回 提交于 2020-01-13 03:39:48
问题 I tried to post an array of data is not sending to server: webservice: deleteCategory() { return this.http.post('http://www.demo/webapi/deletecategory', { headers: { "Authorization": "Token " + this.token, "Content-Type": "application/x-www-form-urlencoded" }, withCredentials: true } ) } in ts file onDelete() { this.userService.deleteCategory().subscribe(response => { this.selectedArray = []; for (var i = 0; i< this.selection._selected.length; i++){ this.selectedArray.push(this.selection.

Angular 6 HttpClient return instance of class

末鹿安然 提交于 2020-01-11 04:58:35
问题 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

Angular Catch method not working with $http get request

安稳与你 提交于 2020-01-07 04:18:07
问题 I am trying to neatly manage service function calls from the controller while handling errors from the API. However when I do the following, I still get this is showing even with 403 and 404 errors in my console even when the API throws back a 403 or 404. I am assuming this could work if I added catch in my services file but I would prefer keep this managed from the controller. Is this possible? Controller: angular.module('EnterDataCtrl', []).controller('EnterDataController', ['$scope', 'Data

Angular: load environment properties before config/run

六月ゝ 毕业季﹏ 提交于 2020-01-07 02:49:35
问题 I'm developing a angular app, and this app has about a 10 configurable properties (depending on the environment and client). I had those properties in json config files, but this is really troublesome: there must be specific builds per env/company. So I would like to retrieve those properties once from the backend on app load. So in order to do this I created a Provider var app = angular.module('myApp', [...]); app.provider('environment', function() { var self = this; self.environment; self

Angular: load environment properties before config/run

可紊 提交于 2020-01-07 02:49:04
问题 I'm developing a angular app, and this app has about a 10 configurable properties (depending on the environment and client). I had those properties in json config files, but this is really troublesome: there must be specific builds per env/company. So I would like to retrieve those properties once from the backend on app load. So in order to do this I created a Provider var app = angular.module('myApp', [...]); app.provider('environment', function() { var self = this; self.environment; self

Angular 2 login not working in safari and firefox

谁都会走 提交于 2020-01-06 07:05:34
问题 For some reason the login part of my application is not working on safari and firefox. I get this error while trying to auth. Now the code is working perfectly in chrome. Signin Service.ts import { Injectable } from '@angular/core'; import { Observable } from 'rxjs/Observable'; import { Http, Headers, RequestOptions } from '@angular/http'; import { HttpWrapper } from '../../../shared/services/http-wrapper.service'; import { SERVER_URL } from '../../../shared/config/config'; import 'rxjs/add