Problem with angular 16 post in mean-stack

17 Views Asked by At

The signup in Angular16 client side:

 onSubmit(): void {
 const { username, email, password } = this.form;
 this.authService.register(username, email, password).subscribe({
  next: data => {
    console.log(data);
    this.isSuccessful = true;
    this.isSignUpFailed = false;
  },
  error: err => {
    this.errorMessage = err.error.errorMessage;   
    this.isSignUpFailed = true;
  }
 });
 }

in the authService file:

 const AUTH_API = 'http://localhost:8080/api/auth/';

 const httpOptions = {
 headers: new HttpHeaders({ 'Content-Type': 'application/json' }),
 //observe: 'response'
 };
 register(username: string, email: string, password: string): Observable<any> {
 return this.http.post(
  AUTH_API + 'signup',
  {
    username,
    email,
    password,
  },
  httpOptions,
 
 );
 }

I just got errorMessage from the code above. thank you!

I tried to add observe: 'response', just got compile error

0

There are 0 best solutions below