Angular16客户端注册:
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;
}
});
}
在 authService 文件中:
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,
);
}
我刚刚从上面的代码中收到了错误消息。 谢谢!
我尝试添加observe: 'response',只是出现编译错误