angular4-httpclient

Angular httpClient returns property does not exist on object

青春壹個敷衍的年華 提交于 2019-12-09 12:56:04
问题 constructor(private http: HttpClient) { } ngOnInit() { this.http.get('url').subscribe(data => { console.log(data); console.log(data.login); }); } } Here, I can see the data with login in console but I get an error saying property login does not exist on data. Is there a workaround for this without using an interface? Because the data I want to get is pretty huge and will probably be modified in the future, so is there any better way? 回答1: The docs state when using HttpClient ... this.http.get

How to post a string in the body of a post request with Angular 4.3 HttpClient?

女生的网名这么多〃 提交于 2019-12-06 18:18:26
问题 We've got a .net WebAPI which looks for a filepath string in the body of a post request and returns the corresponding image. I'm struggling to successfully pass a string to it from Angular 4.3 using the new httpClient. Is it possible? The endpoint's being used by other stuff so I don't really want to create a 'model' of... a string just so I can basically duplicate it but pass it json if possible. WebAPI method signature: public HttpResponseMessage ImagesFromPaths(HttpRequestMessage request,

How to post a string in the body of a post request with Angular 4.3 HttpClient?

﹥>﹥吖頭↗ 提交于 2019-12-04 23:36:39
We've got a .net WebAPI which looks for a filepath string in the body of a post request and returns the corresponding image. I'm struggling to successfully pass a string to it from Angular 4.3 using the new httpClient. Is it possible? The endpoint's being used by other stuff so I don't really want to create a 'model' of... a string just so I can basically duplicate it but pass it json if possible. WebAPI method signature: public HttpResponseMessage ImagesFromPaths(HttpRequestMessage request, [FromBody] string path) Current service method: getImage(path: string): Observable<any> { return this

angular 2/4 multiple drop down

血红的双手。 提交于 2019-12-04 19:56:50
I am trying to develop two drop downs in my Angular application. The 1st one is shop list and the other one is godown list . When I select a shop it will show it on data.but when I select Godown it's not changing data. Here I have two drop down boxes. I think my problem is in my typescript file(Onselect) because here I have 2 drop downs(in html I use 2 Onselect function but in my ts file have only one function). I'm just a beginner in Angular , so I would appreciate any comments on downsides of this method: ngOnInit() { this.Service.FetchPopulateOutlets().subscribe(outletsData => { let

Angular 5 - Observable return error cannot read property of undefined

空扰寡人 提交于 2019-12-04 06:20:11
问题 I'm starting to implement a simple pagination using Spring Rest and Angular 5 inside my angular service when I call my web service using httpClient a get a correct response with the requested page it's display data on my page correctly but there an error the console web browser that there an error inside my *ngFor loop cannot read property of undefined although that the template display results correctly : The problem is in the Service method : getPageClient() and the *ngFor directive This

How to map JSON response to Model in Angular 4

耗尽温柔 提交于 2019-12-03 22:47:25
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 how i call JSON endpoint. result : string[] = []; constructor(private http: HttpClient) { } public

Angular httpClient returns property does not exist on object

时光怂恿深爱的人放手 提交于 2019-12-03 16:07:36
constructor(private http: HttpClient) { } ngOnInit() { this.http.get('url').subscribe(data => { console.log(data); console.log(data.login); }); } } Here, I can see the data with login in console but I get an error saying property login does not exist on data. Is there a workaround for this without using an interface? Because the data I want to get is pretty huge and will probably be modified in the future, so is there any better way? The docs state when using HttpClient ... this.http.get('/api/items').subscribe(data => { // Read the result field from the JSON response. this.results = data[

ERROR Error: StaticInjectorError(AppModule)[UserformService -> HttpClient]:

佐手、 提交于 2019-12-03 11:33:02
问题 While trying to add a PrimeNG table I broke my build here: https://github.com/BillyCharter87/Tech-O-Dex-UI/tree/BrokeIt I recall updating my package.json from TypeScript 2.3.4 to 2.4.0 and it broke due to (I think) the fact that I was using Headers and Http for my POST call. I tried setting it back to 2.3.4 to no avail. I have fixed what I could by adding in: import { HttpClient, HttpHeaders } from "@angular/common/http"; but still running into the Error I have now for the HttpClient . I have

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

瘦欲@ 提交于 2019-12-03 10:07:16
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.propertySystemApiUrl, options) .subscribe((results:any) => { console.log(results); }); } In the Angular code

ERROR Error: StaticInjectorError(AppModule)[UserformService -> HttpClient]:

十年热恋 提交于 2019-12-03 01:01:58
While trying to add a PrimeNG table I broke my build here: https://github.com/BillyCharter87/Tech-O-Dex-UI/tree/BrokeIt I recall updating my package.json from TypeScript 2.3.4 to 2.4.0 and it broke due to (I think) the fact that I was using Headers and Http for my POST call. I tried setting it back to 2.3.4 to no avail. I have fixed what I could by adding in: import { HttpClient, HttpHeaders } from "@angular/common/http"; but still running into the Error I have now for the HttpClient . I have tried importing HttpClient into the providers like so: providers: [HttpClient] for my app.module.ts.