angular4-httpclient

Angular 4: “Http failure response for (unknown URL): 0 Unknown Error”

前提是你 提交于 2020-01-01 04:05:39
问题 I am trying to consume an API URL. I am calling the API with the below code. import {HttpClient, HttpClientModule, HttpParams} from "@angular/common/http"; @Injectable() export class PropertyPrefService { constructor(private http: HttpClient, private configurationService:Configuration) {} public searchProjects(propFilter:string):any{ let temp:any; const options = propFilter ? { params: new HttpParams().set('query', propFilter) } : {}; return this.http.get<any>(this.configurationService

Angular 4: “Http failure response for (unknown URL): 0 Unknown Error”

纵饮孤独 提交于 2020-01-01 04:05:09
问题 I am trying to consume an API URL. I am calling the API with the below code. import {HttpClient, HttpClientModule, HttpParams} from "@angular/common/http"; @Injectable() export class PropertyPrefService { constructor(private http: HttpClient, private configurationService:Configuration) {} public searchProjects(propFilter:string):any{ let temp:any; const options = propFilter ? { params: new HttpParams().set('query', propFilter) } : {}; return this.http.get<any>(this.configurationService

How to intercept request to component html templates in Angular 4.3.5

三世轮回 提交于 2019-12-25 00:56:16
问题 I need to intercept request to the html component templates. Angular version is 4.3.5 . I tried to achieve it with implementing interceptors as described in angular httpClient manual (https://angular.io/guide/http) like that interceptor.service.js import {Injectable} from '@angular/core'; import {HttpEvent, HttpInterceptor, HttpHandler, HttpRequest} from '@angular/common/http'; @Injectable() export class AuthInterceptor implements HttpInterceptor { constructor(private auth: AuthService) {}

How to get image from rest api using HttpClient in angular 4

点点圈 提交于 2019-12-24 22:07:00
问题 I have a simple cuestion. I have the following service in angular 4 app. getProviderPhoto(id:string){ return this.http.get(this.apiUrl+"/"+id+"/images", {responseType: "blob"}); } I need to convert this Blob response to Image file to use the following method: createImageFromBlob(image: Blob) { let reader = new FileReader(); this.photo = new File([image],"foto.png",{ type: 'image/png' }); reader.readAsDataURL(this.photo); reader.onload = (event: any) => { this.image=event.target.result;

How to map JSON response to Model in Angular 4

☆樱花仙子☆ 提交于 2019-12-21 06:26:43
问题 I have tried a lot but I am not able to get endpoint response mapped to my model. I am using HttpClient and Angular4. I got data back from service but it is not mapped correctly to my model class. I have following JSON which service is Returning: { "result": [ { "id": "1", "type": "User", "contactinfo": { "zipcode": 1111, "name": "username" } } ] } I have created a model in typescript which I will like to map to json response: export interface result { zipcode: number; name: string; } This is

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

折月煮酒 提交于 2019-12-18 07:03:31
问题 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),

edit and delete operation in angular

匆匆过客 提交于 2019-12-13 20:06:48
问题 I'm building a crud operation and was able to do the create operation. Now I'm trying to edit and delete them. I tried getting individual data through service but failed. It would be nice if anyone could help me with this. service.ts // Fetch Role Data getRoleData(){ var headers = new HttpHeaders().set('Authorization', 'Token ' + localStorage.getItem('usertoken')); var options_role = { headers: headers }; return this.httpClient.get('api/auth/role/', options_role); } // Add Data sendRole(data)

Angular2/4 post method not working

天大地大妈咪最大 提交于 2019-12-13 04:43:32
问题 I am new in angular2/ 4 web api. I want to save some data to database using angular 4 web api http. When i call a GET method from angular it works fine, but not working on POST method. I am getting 415 Unsupported Media Type.All the time, but when I use postman the post method is work fine because I change the content type to application/json. when i use alert button i get [object,Object],But in angular2/4 it's not working... I see lots of issues with the same problem, but they don't work for

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

点点圈 提交于 2019-12-11 17:15:43
问题 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),

How to read Custom error message from backend in Angular 4/2

限于喜欢 提交于 2019-12-09 19:06:24
问题 API add(data) { return this.httpClient.post<any>('/api/v3/templates', data); } Observable this.templateService.add(obj) .subscribe( (response) => { console.log(reposne) }, (error) => { console.log(error) } ); My Post API gives back a error with some Message in response as Name Already Exists But i am not able to get that in error Object which is printed to console The object which is printed is { error:null headers:HttpHeaders {normalizedNames: Map(0), lazyUpdate: null, lazyInit: ƒ} message: