Set focus on element

Edit 2022: Read a more modern way with @Cichy’s answer below Modify the show search method like this showSearch(){ this.show = !this.show; setTimeout(()=>{ // this will make the execution after the above boolean has changed this.searchElement.nativeElement.focus(); },0); }

Confirm password validation in Angular 6 [duplicate]

This question could be solved with a combination of these two answers: https://stackoverflow.com/a/43493648/6294072 and https://stackoverflow.com/a/47670892/6294072 So first of all, you would need a custom validator for checking the passwords, that could look like this: checkPasswords: ValidatorFn = (group: AbstractControl): ValidationErrors | null => { let pass = group.get(‘password’).value; let confirmPass = group.get(‘confirmPassword’).value return pass === … Read more

Angular error: “Can’t bind to ‘ngModel’ since it isn’t a known property of ‘input'”

In order to use two-way data binding for form inputs you need to import the FormsModule package in your Angular module. import { FormsModule } from ‘@angular/forms’; @NgModule({ imports: [ FormsModule ] EDIT Since there are lot of duplicate questions with the same problem, I am enhancing this answer. There are two possible reasons Missing … Read more