angular-httpclient

Type “json” | undefined not satisfied by “json” in Angular HttpClient

人盡茶涼 提交于 2020-07-09 07:19:03
问题 I'm scrutinizing the docs for HttpClient, focusing on the get(...) method. I've prepared the following sample: const headers: HttpHeaders = new HttpHeaders(); const observe: HttpObserve = null; const params: HttpParams = new HttpParams(); const reportProgress = false; const responseType = "json"; const withCredentials = true; const options = { headers, observe, params, reportProgress, responseType, withCredentials }; this.http.get(url, options) I get an error stating the following. No

Handling CORS when calling 3rd party API

强颜欢笑 提交于 2020-06-26 13:32:18
问题 yes this is a very famous question , I have tried many ways mentioned in the previous stack-overflow QnA, but nothing worked. I am trying to use BANZAI-Cloud API in my application , but it gives the following error here is my code of the service class import { Injectable } from '@angular/core'; import {HttpClient} from '@angular/common/http'; import { Observable } from 'rxjs'; import { HttpHeaders } from '@angular/common/http'; @Injectable({providedIn:"root"}) export class PriceTableService{

How to add a body to Angular HttpClient delete function

半城伤御伤魂 提交于 2020-05-25 05:40:49
问题 Our project is migrating to Angular4 , and use @angular/common/http Httpclient as the default network tool. But I found there are no body params in delete function. How do I add the body to delete function? Thanks. 回答1: You may use a universal request method on the HttpClient class instead. This method has the body in options. https://angular.io/api/common/http/HttpClient#members e.g this.http.request('delete', 'url', { body: ... }) 回答2: const httpOptions = { headers: new HttpHeaders({

How to implement this angular-tree-component async data code?

不羁岁月 提交于 2020-04-17 20:40:13
问题 I am having trouble implementing this https://angular2-tree.readme.io/docs/async-data-1 . How do I rewrite the following code from OnInit to be async like in the documentation?: this.client.get(API_URL, this.httpOptions).subscribe( (res) => { this.nodes.push(res) }, (error) => { this.handleError(); } ); Please also refer to this question How to store HttpClient GET fetched data into a variable? 回答1: Making a tree as asyn means, you can fetch it's childrens when their parent node expands

How to implement this angular-tree-component async data code?

好久不见. 提交于 2020-04-17 20:38:29
问题 I am having trouble implementing this https://angular2-tree.readme.io/docs/async-data-1 . How do I rewrite the following code from OnInit to be async like in the documentation?: this.client.get(API_URL, this.httpOptions).subscribe( (res) => { this.nodes.push(res) }, (error) => { this.handleError(); } ); Please also refer to this question How to store HttpClient GET fetched data into a variable? 回答1: Making a tree as asyn means, you can fetch it's childrens when their parent node expands

How to use BehaviourSubjects to share data from API call between components in Angular?

蓝咒 提交于 2020-04-07 08:09:06
问题 I am currently building an Angular application where I make a request to an api, and I map the repsonse to two different arrays. I can use this data in my app.components.ts but I will make new components for what I need. How can I share the data between components to ensure that the components always have the latest data because I will also need to periodically call the API. I've seen some answers on SO and some youtube videos but I'm just not fully understanding it. The code of my service is

Catching errors in Angular HttpClient

℡╲_俬逩灬. 提交于 2020-03-07 05:49:29
问题 I have a data service that looks like this: @Injectable() export class DataService { baseUrl = 'http://localhost' constructor( private httpClient: HttpClient) { } get(url, params): Promise<Object> { return this.sendRequest(this.baseUrl + url, 'get', null, params) .map((res) => { return res as Object }) .toPromise(); } post(url, body): Promise<Object> { return this.sendRequest(this.baseUrl + url, 'post', body) .map((res) => { return res as Object }) .toPromise(); } patch(url, body): Promise

How to get response headers - Issue with getting response headers

☆樱花仙子☆ 提交于 2020-02-26 02:57:54
问题 I'm passing pagination information in response header and unable to get using following method in angular 8. I'm getting 0 all the time but in response showing diffrent value. Can anyone let me know where I made mistake? app.service.ts indexBooking(perPage: number, page: number) { return this.http .get<any[]>(`${this.apiBaseUrl}/prices`, { params: formatParameters({perPage, page}), observe: 'response', }) .pipe( map((res) => ({ max: Number.parseInt(res.headers.get('x-total-count'), 10) || 0,

Not using the base attribute when making DomSanitizer API calls?

强颜欢笑 提交于 2020-01-24 20:52:22
问题 I'm making a call using the DomSanitizer like this: this.domSanitizer.bypassSecurityTrustResourceUrl(url)); The url is complete URL to the SVG image being fetched. Here's is an example: this.matIconRegistry.addSvgIcon( "fs", this.domSanitizer.bypassSecurityTrustResourceUrl('https://github.com/fireflysemantics/images/blob/master/fsalpha/logo/fsalpha-logo-optimized.svg')); However since base is set to another URL in index.html , the dom sanitizer URL is prefixed with it. Is there a way to

Poll API using Angular HTTP Observable

拟墨画扇 提交于 2020-01-23 12:26:05
问题 In my component html, I am using the asyncPipe to subscribe to this http service. The service maps the json response object to an array of class instances. This all works great, but I would like http service to poll every few seconds. I've tried a bunch of things (like interval), but it seems RXJS is a bit of a minefield at the moment. Has anyone implemented this kind of thing using Angular 6? fetch(command, params?) { return this.http.post(`http://localhost:4000/${command}`, params) .pipe(