angular4-httpclient

Http Get Response Updates HTML but giving undefined error in console

 ̄綄美尐妖づ 提交于 2019-12-02 22:56:20
问题 When I am updating my html with the response Obj using HttpClient it updates the values but gives multiple errors. File Name - auth-service.ts. import { any } from 'codelyzer/util/function'; import { Injectable } from '@angular/core'; import { HttpClient } from '@angular/common/http'; @Injectable() export class AuthService { constructor(private httpClient: HttpClient) { } get() { return this.httpClient.get<any>('/capi/v2/users/me', { observe: 'body', responseType: 'json' }); } }; File Name -

Call another httpCall before actual call usng Angular's HttpInterceptor

不问归期 提交于 2019-12-01 00:35:13
I'm using HttpInterceptor api of new Angular HttpClientModule and now stuck with a situation. Here is my use-case. In my application, if any service makes an http call, I want to make another silent http call before it, and want to store it's result locally. Once the silent call is completed, then only I'll proceed with the service's http call and will return its result. Here is what I'm doing. (Using HttpInterceptor) intercept(req: HttpRequest<any>, next: HttpHandler): Observable<HttpEvent<any>> { if (req.url.match(/api\//)) { // api call http.post('/auth/silentCall', {user: 123}).subscribe(

Loader Using HttpClient Interceptor Angular 4

浪子不回头ぞ 提交于 2019-11-30 22:39:44
How can i implement a loader using Angular 4 HttpClient Interceptor? I have done the login and attaching the authorization header and i wonder if i can also do the "loader function" if some data is loading in the process? I would like to attached a icon loader that signals if some data is loading. Here's my authinterceptor below by the way. export class GithubAuthInterceptor implements HttpInterceptor { intercept (req: HttpRequest<any>, next: HttpHandler): Observable<HttpEvent<any>> { const authReq = req.clone({ headers: req.headers.set('Authorization', 'token') }); return next.handle(authReq)

Call another http api (without Intercepting) before actual http call is made in Angular's HttpInterceptor

隐身守侯 提交于 2019-11-30 20:40:29
问题 I'm using HttpInterceptor api of Angular's HttpClientModule and now stuck with a situation. Here is my use-case. In my application, if any service makes an http call, I want to make another silent http call before it, and want to store it's result locally. Once the silent call is completed, then only I'll proceed with the service's http call and will return its result. Here is what I'm doing. (Using HttpInterceptor) intercept(req: HttpRequest<any>, next: HttpHandler): Observable<HttpEvent<any

Loader Using HttpClient Interceptor Angular 4

与世无争的帅哥 提交于 2019-11-30 17:29:30
问题 How can i implement a loader using Angular 4 HttpClient Interceptor? I have done the login and attaching the authorization header and i wonder if i can also do the "loader function" if some data is loading in the process? I would like to attached a icon loader that signals if some data is loading. Here's my authinterceptor below by the way. export class GithubAuthInterceptor implements HttpInterceptor { intercept (req: HttpRequest<any>, next: HttpHandler): Observable<HttpEvent<any>> { const

Angular 4 single API request running multiple times

荒凉一梦 提交于 2019-11-29 16:00:58
I am having issue regarding Angular 4 App. I have created an app in which data is getting from third party APIs. The issue I am getting is my APIs are calling for multiple times but I sent request only once. After some R&D I found browser is running flight request with OPTION method but after checking all APIs I found they are running for multiple times except flight request. Like fir an API I am requesting API once and it is running for 4 times 2 times for option and 2 times for GET request.I check my code and only one time request is running. I totally understand and agree with flight

Can't have a timeout of over 2 minutes with this.http.get?

蹲街弑〆低调 提交于 2019-11-29 12:22:39
My angular 4.3.2 code is calling my back-end service that takes 2-4 minutes to return. Using just the default this.http.get code, I see that the default timeout kicks in after 2 minutes. However when I try to put in a timeout of anything OVER 2 minutes, it fails in that it will never let the timeout be over 2 minutes. I've tried with 100, 100000 (1.7m) and 114000(1.9m) and those work in that it gets timed out right at those values. But when I try 126000 (2.1m), 180000 (3m) and 1800000 (30m), again I see it times out after 2 minutes. this.http.get('myUrl') .timeout(126000) .map((res: Response)

ASP.NET Core 2.0 and Angular 4.3 File Upload with progress

喜夏-厌秋 提交于 2019-11-28 19:01:14
Using the new Angular 4.3 HttpClient , how can I upload and access files in an ASP.NET Core 2.0 Controller while reporting upload progress to the client? Here is a working example to get started: HTML <input #file type="file" multiple (change)="upload(file.files)" /> <span *ngIf="uploadProgress > 0 && uploadProgress < 100"> {{uploadProgress}}% </span> TypeScript import { Component } from '@angular/core'; import { HttpClient, HttpRequest, HttpEventType, HttpResponse } from '@angular/common/http' @Component({ selector: 'files', templateUrl: './files.component.html', }) export class

Angular 4 single API request running multiple times

倾然丶 夕夏残阳落幕 提交于 2019-11-28 10:19:53
问题 I am having issue regarding Angular 4 App. I have created an app in which data is getting from third party APIs. The issue I am getting is my APIs are calling for multiple times but I sent request only once. After some R&D I found browser is running flight request with OPTION method but after checking all APIs I found they are running for multiple times except flight request. Like fir an API I am requesting API once and it is running for 4 times 2 times for option and 2 times for GET request

ASP.NET Core 2.0 and Angular 4.3 File Upload with progress

醉酒当歌 提交于 2019-11-27 12:08:54
问题 Using the new Angular 4.3 HttpClient, how can I upload and access files in an ASP.NET Core 2.0 Controller while reporting upload progress to the client? 回答1: Here is a working example to get started: HTML <input #file type="file" multiple (change)="upload(file.files)" /> <span *ngIf="uploadProgress > 0 && uploadProgress < 100"> {{uploadProgress}}% </span> TypeScript import { Component } from '@angular/core'; import { HttpClient, HttpRequest, HttpEventType, HttpResponse } from '@angular/common