I am getting data and display it inside an input of a reactive form:
<div *ngFor="let users of getUsersArray; let i = index;">
<mat-form-field>
<input matInput color="warn"
[value]="users.role_type"
formControlName="edit_role_type" placeholder="Role Type">
</mat-form-field>
</div>
This form control is created inside a reactive form:
'edit_role_type': new FormControl({value:'', disabled: true}, Validators.required),
I have an update button, so if a user wants to update the field with new data:
<button mat-raised-button color="warn"
(click)="updateUser(users)" [disabled]="formGroup4.valid">
<mat-icon>update</mat-icon> Update Data
</button>
If I console the value of users on update button click, I can see the data generated from the *ngFor.
If I changed the value and console it, I only see the old values and the new typed one isn't displayed.
Here is the update button script:
updateUser(users){
console.log(users)
let email = this.formGroup4.controls['edit_user_email'].value;
if(this.formGroup4.get('edit_user_password').hasError('minLength'))
{
//Password error
}
else if(email!='' && !email.endsWith('@test.org'))
{
//return email error
}
else
{
this.auth.updateUserData(users).subscribe(
(data)=>{
},
(error)=>{
console.log(error)
}
);
}
}
getUsersArrayis a simple array that we iterate over to display data sent from server using*ngFor