angular2-http

Resend request angular 2

北城以北 提交于 2019-12-10 20:08:47
问题 In angular 2 app every request to API has header with token, in case token has expired API responds with 401 http code. I have a method to update token, but how I can resend previous request pausing others while a new token is in the process of getting? 回答1: You could extend the Http class for this this way, catch the error using the catch operator of observables: An approach could be to extend the HTTP object to intercept errors: @Injectable() export class CustomHttp extends Http {

How to mock service?

ⅰ亾dé卋堺 提交于 2019-12-10 17:47:10
问题 I have login function inside my LoginComponent: login() { this.loading = true; this.subscription = this.authenticationService.login(this.model.username, this.model.password) .subscribe(result => { this.em.changeNav(1); this.loading = false; this.Auth.setToken(result); this.router.navigate(['/code']); this.subscription.unsubscribe(); }, err => { this.error = JSON.parse(err._body).error; this.loading = false; }); } this.authenticationService.login is the service which send http request to api..

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

假装没事ソ 提交于 2019-12-10 01:04:39
问题 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

How to do a async HTTP request inside an Angular2 loop/map and modify the original loop array?

北慕城南 提交于 2019-12-09 18:27:27
问题 New to Angular2 here and wondering how to do this async request on array pattern (not so sure about the pattern name). So let's say I use Angular2's Http to get a YouTube Playlist that contains videoId in each return item. Then I need to loop through this item with the videoId and do another request to YouTube to get the individual video information. This can be another common HTTP request, get the list then loop through the list and get the details of every individual item. let url =

Angular2 Http Response missing header key/values

爷,独闯天下 提交于 2019-12-08 16:45:39
问题 I'm making an http.patch call to a REST API that is successful (Status 200) but not all the response headers key/values are being returned. I'm interested in the ETag key/value. Here is a code snippet: let etag:number = 0; let headers = new Headers(); headers.append('Content-Type', 'application/json'); headers.append('If-Match', String(etag)); this.http.patch( 'http://example.com:9002/api/myresource/', JSON.stringify(dto), {headers: headers} ) .subscribe( (response:Response) => { let headers

Concatenation of Angular http requests

怎甘沉沦 提交于 2019-12-07 19:41:31
问题 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

Angular 2 Http timeout

徘徊边缘 提交于 2019-12-07 08:04:18
问题 I have a problem posting a custom error message on HTTP timeout. Here is the simple example: return this._http.get(url).timeout(5000, new Error("Error message")); I saw that everybody uses new Error("Error message") but I'm getting the error: Error function expects type Scheduler. I'm getting this error: Argument of type 'Error' is not assignable to parameter of type 'Scheduler'. Property 'SchedulerAction' is missing in type 'Error' 回答1: In rxjs 4, it was possible to customise the error

angular2-in-memory-web-api 404 error

假如想象 提交于 2019-12-07 06:56:50
问题 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

angular2 posting XML type request data using HTTP

此生再无相见时 提交于 2019-12-07 04:44:12
问题 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

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

*爱你&永不变心* 提交于 2019-12-06 20:07:24
问题 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