I am developing an application in Angular which involves creating, reading, updating, and deleting user information. I have a requirement for the username to be unique and need to display an error message if it is not unique, while also focusing on the username field. I have successfully implemented the error handling but I am facing difficulties in setting the focus back to the username field.
Any assistance with this matter would be greatly appreciated.
Below is my TypeScript code:
export class AdduserComponent implements OnInit {
constructor(
private formBuilder: FormBuilder,
private userService: UsersService,
private router: Router,
private snackBar: MatSnackBar
) { }
addForm: FormGroup;
passwordsMatcher = new RepeatPasswordEStateMatcher;
ngOnInit() {
// Form initialization logic
}
onSubmit() {
// Form submission logic
}
changeClient(value) { }
resetForm() {
// Reset form function
}
}
Below is the HTML code:
<div style="height: 100vh" fxLayout="column" fxLayoutAlign="center center">
<mat-toolbar class="toolbar">
<span class="span">Create New NI User</span>
</mat-toolbar>
<mat-card class="card">
<mat-card-content>
<!-- Form content goes here -->
</mat-card-content>
</mat-card>
</div>