below is my code, I just want to query the backend if email already registered or not, however, no matter what email I pass to the verifyEmail function, the "registered" variable always false, how can I update the registered variable according to the backend response ? Thanks
export class MyClass { registered: boolean = false; message: string = '' verifyEmail(email) { this.registered= false let verifyEmailUrl = "/backend/GetUserByEmail"; this.http.post(verifyEmailUrl, { email: email }).subscribe( (data) => { if (data["user"]) { // can find a user this.message = 'This email has already been registered' this.registered= true } }); }
https://stackoverflow.com/questions/66082798/angular-typescript-could-not-update-outside-variable-in-the-subscribe-functi February 07, 2021 at 06:51AM
没有评论:
发表评论