angular-httpclient

How to read the status from response in angular http?

ぐ巨炮叔叔 提交于 2019-12-11 05:23:55
问题 I am facing some problem in reading the status code from response. I am calling api in service, return this.http.get<string>( this.remoteServer + '/google.com/open', httpOptions); In my controller I have, open() { this.openService.open(this.selected.qrCode) .subscribe( data => { console.log(data); this.toastService.showSuccess('Unlock Successfull', 'success'); } ); } Now I want to read the http statustext, the sample http response I am getting from the above call is. HttpErrorResponse

What is cold observable in context of angular HttpClient

自闭症网瘾萝莉.ら 提交于 2019-12-11 01:47:59
问题 While using angular HttpClient of angular I got to know that HttpClient post method used cold observable and will make 2 separate calls to post data to the server.And also unless you will not subscribe the post method it will not post data to the server. Although, Rxjs cold observable says it will hold all the sequence until the the end and fire all when it subscribed. How it will make 2 separate call to server to post data. 回答1: I don't believe that this behavior is caused by the use of

How to perform caching http get request in angular 5?

百般思念 提交于 2019-12-10 23:25:56
问题 import { Injectable } from '@angular/core'; import { HttpClient, HttpErrorResponse } from '@angular/common/http'; import { Observable } from 'rxjs'; import { catchError } from 'rxjs/operators'; @Injectable() export class ApiService { constructor(private http: HttpClient) { } // get API request public apiGetRequest(url: any): Observable<any> { return this.http.get(url) .pipe( catchError(this.handleError('apiGetRequest')) ); } } I am using angular 5 with rxjs version 5.5.6 I am trying to cache

HTTP get call in Angular 6

点点圈 提交于 2019-12-10 14:05:10
问题 I updated my Angular project to Angular 6 and don't know how to do http get requests. Thats how I did it in Angular 5: get(chessId: string): Observable<string> { this.loadingPanelService.text = 'Loading...'; this.loadingPanelService.isLoading = true; const url = `${this.apiPathService.getbaseUrl()}api/chess/${chessId}/rating`; return this.http.get<string>(url) .catch((error) => { console.error('API error: ', error); this.loadingPanelService.isLoading = false; this.notificationService

Update list when new item is added

我只是一个虾纸丫 提交于 2019-12-10 12:12:30
问题 Using Angular 7 I have the following service (StackBlitz Example): @Injectable({ providedIn: 'root' }) export class TodoService { todos: BehaviorSubject<Todo[]> = new BehaviorSubject([ { id: 1, title: "Buy book", content: "Buy book about angular" }, { id: 2, title: "Send invoice", content: "Send invoice to client A" } ]); public get(): Observable<Todo[]> { return this.todos.asObservable(); } public create(todo: Todo) { this.todos.next(this.todos.value.concat(todo)); } } This service is used

HttpHeader isn't correctly sent

为君一笑 提交于 2019-12-10 11:48:59
问题 I am coding according to this guide: https://angular.io/guide/http#configuring-other-parts-of-the-request. My code is the following: loadMenuOptions(): void { console.log('this.currentApiKey |' + this.currentApiKey); let header = new HttpHeaders(); header = header.set('api-key', this.currentApiKey); this.commonService. getMenuOptions(MENU_OPTIONS, header).subscribe(respuesta => this.setMenuOptions(respuesta)); } The following code is when I send this object to the server: getMenuOptions

Overload request headers and params with HttpClient get

可紊 提交于 2019-12-10 11:04:08
问题 In HttpClientModule, is there a method to pass headers and params to get request. import { HttpHeaders, HttpParams, HttpClient } from @angular/common/http'; const headers = { headers: new HttpHeaders({}) } let params = new HttpParams({ }); get(url, {params}) // http client get with params get(url, {headers}); //http client get with headers I want something like requestoptions to hold both or a syntax to do httpClient get sending request headers and params. Currently building complete url with

Calling Spring boot api that downloads a pdf from Angular 6 is giving error can't parse response

巧了我就是萌 提交于 2019-12-10 10:06:44
问题 I have a spring boot API that creates a pdf report and download it, if I call the API directly in the browser, the pdf is created and downloaded directly, but when I call that GET API from Angular 6 I get the following error: The Spring boot (java) code: @RequestMapping(value = "/app_report/en", method = RequestMethod.GET) @ResponseBody public void getEnRpt(HttpServletResponse response, @RequestParam("appNum") String appNum) throws JRException, IOException, SQLException { JasperReport

Angular 6 : HttpHeaders Cannot read property 'length' of null in Chrome and IE11 (and not in Firefox)

元气小坏坏 提交于 2019-12-10 09:37:37
问题 Under my Angular6 app , i'm using HttpClient with some headers injection to my htpp calls to fetch data from my backend server : My service : @Injectable() export class LoadUserInfosService { public _headers = new HttpHeaders().set('Content-Type', 'application/json'); constructor(private httpClient: HttpClient) {} getUserPnsInfos(cuid): Observable<object> { const headers = this._headers.append('login', login); return this.httpClient.get(myBackUrl, {headers: headers}); } } My component where i

Angular 5: Http failure response for (unknown url): 0 Unknown Error in EDGE browser when calling api

橙三吉。 提交于 2019-12-10 08:34:20
问题 I have a angular 5 application which calls a .NET Core 2.0 backend api. Call to the API from the angular service works fine in all browsers (Chrome, Firefox, IE11) but not in EDGE. In EDGE, i am getting the error Http failure response for (unknown url): 0 Unknown Error. It is a CROSS ORIGIN CALL and Cors has been enabled in the API as below. Right now i am enabling for any origin services.AddCors(options => { options.AddPolicy("AllowAllOrigins", builder => { builder.AllowAnyOrigin()