question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Post Undefined HttpClient

See original GitHub issue

Hi there, i recently upgraded from V7 to V8 using the guide provided. Prior to this i was using HttpClient for my post requests and it went along fine. After the update i get a TypeError: Cannot read property 'post' of undefined i’ve been over the code a dozen times and for the life of me i can’t seem to find what’ is wrong with it.

import { Injectable } from '@angular/core';
import { HttpClient, HttpHeaders } from '@angular/common/http';
@Injectable({
  providedIn: 'root'
})
  constructor(private httpClient: HttpClient) {}

  GetCountry(): Observable<any> {
    return this.httpClient.post(
      this.apiURL + '/country/list',
      JSON.stringify({
        api_key: this.apiKey
      }),
      this.httpOptions
    );
  }

Thanks

Issue Analytics

  • State:closed
  • Created 4 years ago
  • Reactions:3
  • Comments:13 (6 by maintainers)

github_iconTop GitHub Comments

2reactions
bkr32commented, Jun 15, 2019

thanks for your suggestion @maxigimenez i reverted to a commit before the v8 update, cleared npm cache cleared node modules did a npm install and then a ng update it all worked out well after that

1reaction
maxigimenezcommented, Jun 6, 2019

Try a fresh install of package.json also clearing npm cache and removing node_modules.

Read more comments on GitHub >

github_iconTop Results From Across the Web

HttpClient instance is undefined in Angular 6 service
1. When injecting the httpClient, it's a private rather than public constructor(private http: HttpClient) { } · 2. I think you need to...
Read more >
httpClient is undefined : r/Angular2 - Reddit
I've been getting an error in my browsers terminal when it attempts to execute a very short, simple function that does an http...
Read more >
Communicating with backend services using HTTP - Angular
An app can send PUT requests using the HTTP client service. The following HeroesService example, like the POST example, replaces a resource with...
Read more >
HttpClient - Angular
Constructs an observable for a generic HTTP request that, when subscribed, fires the request through the chain of registered interceptors and on to...
Read more >
Angular Basics: How To Use HttpClient in Angular - Telerik
options – It is used to configure the HTTP request. It is optional and of type object , and its default value is...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found