title: Why Angular HTTP Post method Error: Cannot read property 'post' of undefined?
body: <blockquote>
  <p>Angular HTTP Post method  Error: Cannot read property 'post' of undefined.
  I am trying to make my first http POST request.But it not working</p>
  </blockquote>
  <pre><code>
  
  export class RegisterComponent implements OnInit {
    [x: string]: any;
  
  firstnameControl = new FormControl();  //To get values
  
  
    hide=true;
    constructor( ) { }
  
    ngOnInit(): void {
    }
  
  
    signup(){
      //1.Collect Parameters
      let body = new HttpParams({
        fromObject:{
            'firstname': this.firstnameControl.value,
        }
      });
      
      //2.Send to URL
      var url =&quot;http://52.15.72.215:3000/api/user&quot;;
      this.http.post(url ,body).subscribe(
        ( data: any) =&gt;{
            alert(data);
          }
      );
      
    }
  
    
  
  }
  
   
  
  </code></pre>
  <blockquote>
  <p>Why this post method not working</p>
  </blockquote>
  <hr />