angular2-http

Concatenation of Angular http requests

巧了我就是萌 提交于 2019-12-06 13:52:38
I am facing the following scenario. There is a Front End app, built with Angular(2), which is connected with a REST Back End accessible via http. Once an user logs in (using email and pwd), the Back End returns data related to the user and in particular an id associated with the user (let's call this userId ) and the code of the region where he lives (let's call this regionId ). Via the userId I can query the Back End to get the affinity group ID to which the user belongs (let's call this affinityId ). Finally, using affinityId and regionId I can retrieve from the Back End the discount to

Angular 2 “No provider for String!”

余生颓废 提交于 2019-12-06 06:00:32
I'm trying to create a generalized data service in Angular 2, and I'm encountering a strange error. Essentially, I'm creating an HTTP service whose methods take in part of the api url so that I can use it for multiple cases. For example, I would like to pass in 'projects/' and join it with 'api/' to get 'api/projects/' which I could then use in the http calls. My current dataService.ts: import { Injectable } from '@angular/core'; import { Http, Response, Headers } from '@angular/http'; import 'rxjs/add/operator/map' import { Observable } from 'rxjs/Observable'; import { Configuration } from '.

Upgrade Http to HttpClient in Angular 5: “server responded with a status of 415 (Unsupported Media Type)”

心不动则不痛 提交于 2019-12-06 04:55:32
问题 I've upgraded an app from Angular 4.2 to 5 but after changed Http to HttpClient got error on POST request: error the server responded with a status of 415 (Unsupported Media Type) in app.module I've imported HttpClientModule : import { HttpClientModule } from '@angular/common/http'; Old code: post(url: string, model: any): Observable<any> { let body = JSON.stringify(model); let headers = new Headers({ 'Content-Type': 'application/json' }); let options = new RequestOptions({ headers: headers }

angular2-in-memory-web-api 404 error

Deadly 提交于 2019-12-05 10:51:20
I'm trying to build the 5 min app in angular 2 by this guide: https://angular.io/docs/ts/latest/tutorial/toh-pt6.html . In the http part, I added a fake server but I get 404 error because the angular2-in-memory-web-api. http://localhost:4200/vendor/angular2-in-memory-web-api/in-memory-backend.service.js Failed to load resource: the server responded with a status of 404 (Not Found) I was trying to follow this answer: Angular2 Tutorial (Tour of Heroes): Cannot find module 'angular2-in-memory-web-api' But he didn't use angular-cli + I don't have a clue where to add those dependencies they talked

angular2 posting XML type request data using HTTP

不问归期 提交于 2019-12-05 09:54:37
I am able to post the JSON request data to server in the following way, but how do i post XML structured data to server using http. getAuthSeed(value) { let params = "{'validateUsr': 'false'}"; let headers = new Headers(); headers.append('Content-Type', 'application/json'); headers.append('params', params); let url = 'tab-api/login/'+value.username+'/seed/false'; let options = new RequestOptions({ method: RequestMethod.Get, url: url, headers: headers }); return this.http.request(new Request(options)).map( result => { let data = result.json(); return data; } ) } sample XML request: <pi:ReqPay

How to Map Response object returned by Http Service to a TypeScript Objects using Observable Map function in Angular2

*爱你&永不变心* 提交于 2019-12-05 02:35:27
Hi I have created an angular2 service whose task is to call a webapi which returns data in a json object structure as follows: //Result of the webapi service call. { "Total":11, "Data":[{"Id":1,"Name":"A","StartDate":"2016-01-01T00:00:00"}, {"Id":2,"Name":"B","StartDate":"2016-02-01T00:00:00"}] } Here is my angular2 service. The getMileStones methods work perfectly and I am able to cast the response back to MileStone[] . But In order to get the paged data I have created a function getPagedMileStones(int,int) which call a webapi method and return the result as mentioned above structure .I want

Angular2 HTTP - How to understand that the backend server is down

爷,独闯天下 提交于 2019-12-05 01:01:10
I am developing a front end which consumes JSON services provided by a server. I happily use HTTP of Angular2 and I can catch errors via .catch() operator. If I find a problem related to a specific service (e.g. the service is not defined by the server) the catch() operator receives a Response with status 404 and I can easily manage the situation. On the other hand, if it is the server that is completely down, the catch() operator receives a Response with status code 200 and no specific sign or text related to the cause of the problem (which is that the whole server is down). On the console I

How can I get access to the Angular 2 http response body without converting it to string or json?

ⅰ亾dé卋堺 提交于 2019-12-04 15:32:16
问题 I would like to copy a REST response into a blob but I am unable to do some because blob() and arrayBuffer() have not yet been implemented in the Response Object. The Response Body is a private variable. ... return this.http.get(url, {params: params, headers: headers}) .map(res => { // can't access _body because it is private // no method appears to exist to get to the _body without modification new Blob([res._body], {type: res.headers.get('Content-Type')}); }) .catch(this.log); ... Is there

rxjs with multiple forkjoin when doing http requests

依然范特西╮ 提交于 2019-12-04 02:16:01
问题 I am doing some http requests and use rxjs for successfull notification of the result: getReportings(departmentId: number): Observable<any> { return Observable.forkJoin( this.http.get('/api/members/' + departmentId).map(res => res.json()), this.http.get('/api/reports/' + departmentId).map(res => res.json()) ); } When both http requests are done I want inside the getReportings method to iterate the reports array , read some values and for each report make again a new http request with those

Cannot find module './in-memory-data-service' in tour of heroes for Angular2

北城余情 提交于 2019-12-03 09:28:47
I am trying to work through the Angular2 tour of heroes app, and am running into bugs on the Http section of the tutorial . At first I was getting the error: Cannot find module 'angular2-in-memory-web-api' But fixed that using the information from this question . However, at this same step I'm also getting the following error: app/app.module.ts(10,38): error TS2307: Cannot find module './in-memory-data-service'. I've triple checked and I believe both my in-memory-data-service.ts file and my app.module.ts file are exactly the same as listed in the tutorial (at this particular point in time).