0

I am trying to call Http Post with Angular 5 and send it to my back end (which uses springboot and MySQL). Having tested backend with Postman , that seems to work. It is when I'm trying to put Angular in the game that it doesn't seem to work. There are no compile or console errors and nothing is received by spring. The code for the correspondent Angular Service is the following:

The post method is inside the registerProvider method at the bottom: I'd like to point out that the console.logs used there also print the proper data so it's not a matter of the ..component.html either

import { Injectable } from '@angular/core';

import { OnInit } from '@angular/core';

import { Router } from '@angular/router';

import { HttpClient } from '@angular/common/http';

import {Observable} from 'rxjs/Observable';
import { of } from 'rxjs/observable/of';

import { IProvider } from './provider';

@Injectable()
export class ProviderService {

constructor(private router: Router,
            private httpClient: HttpClient ){}

private provider: IProvider= {'email':undefined,'password':undefined};

getProvider(): IProvider {
    return this.provider;
}

getProviderEmail(): string{
    return this.provider.email;
}

getProviderPassword(): string{
    return this.provider.password;
}

setProviderEmail(email: string): void {
    this.provider.email= email;
}

setProviderPassword(password: string): void {
    this.provider.password= password;
}

checkProvider(email: string, password: string): boolean{
    if(email=='provider@a.a' && password=='a'){ //validation of provider
      this.provider.email= email;
      this.provider.password= password;
      return true;
    }
    return false;
}

logOut(): void{
    this.setProviderEmail(undefined);
    this.setProviderPassword(undefined);
    this.router.navigate(['/']);
}

isProviderLogged():boolean{
    return !!(this.getProviderEmail() && this.getProviderPassword());
}

registerProvider(email: string, password: string): Observable<any> {
    console.log(email,password);
    this.setProviderEmail(email);
    this.setProviderPassword(password);
    let backendUrl: string = 'http://localhost:8080/signUpProvider';
    console.log(backendUrl);
    console.log(this.provider);
    return this.httpClient.post<any>(backendUrl, this.provider,{observe : 'response'});
   }
}
Makis Kans
  • 337
  • 3
  • 12
  • 3
    Are you subscribing to the Observable returned by `registerProvider`? If you don't subscribe to it, it won't be called. – Tim Sep 25 '18 at 17:53

1 Answers1

0

you need to subscribe to the observable from where you are calling the registerProvider function.

inside the component file where you are calling the register provider function, add a subscription.

registerProvider(email, password).subscribe((res) => {

})
Franklin Pious
  • 3,670
  • 3
  • 26
  • 30