Ansyc code does not working, I m using angular 11

Hello Guys I trying to do the exercise “Solution- Change Password Form”, but async control does not working, anybody know how can help me?

export class ChangePasswordComponent implements OnInit {
form: FormGroup;
constructor(fb: FormBuilder) {
this.form = fb.group({
oldPassWord: [
‘’, [Validators.required, PasswordValidator.validOldPassword, Validators.minLength(4),] ],
newPassWord: [’’, Validators.required],
confirmPassWord: [’’, Validators.required],
});
}
ngOnInit(): void {}

get oldPassword() {
return this.form.get(‘oldPassWord’);
}

get newPassword() {
return this.form.get(‘newPassWord’);
}

get confirmPassword() {
return this.form.get(‘confirmPassWord’);
}

changePassword() {
console.log(this.form.errors);
}

//----------------------------------------------------------------- template

Old Password
Old Password is Required
Min Length 4 Caracters
Old Password Is Invalid
New Password
New Password is Required
Min Length 4 Caracters
Confirm New Password
New Password is Required
Min Length 4 Caracters
Change and Save
// ---------------------------------------------------------------------Async class export class PasswordValidator { static validOldPassword(control: AbstractControl): Promise{ return new Promise((resolve, reject ) => { if(control.value !=='12345'){ resolve({ invalidOldPassword: true }); } else { resolve(null); } }); } }
1 Like

Would you mind reformatting your code using codeblocks so that it is more readable?

For example:

export class PasswordValidator {
  static validOldPassword(control: AbstractControl): Promise{
    return new Promise((resolve, reject ) => {
      if(control.value !=='12345') {
        resolve({ invalidOldPassword: true });
      } else {
        resolve(null);
      }
    });
  }
}

Were you able to resolve your issue? I know that many of the APIs have changed since Angular 4 (which is the version the course was written for).