I have component called edit-customer which is an dialog window, which will receive the injected object from other component and will display that injected object properties(name,email).Below is the component code.
HTML
<form [formGroup]="editForm">
<mat-form-field >
<input matInput [(ngModel)]="data.name" placeholder="Name" formControlName="name" >
</mat-form-field>
<mat-form-field >
<input matInput [(ngModel)]="data.EMailAddresses" placeholder="Email Id" formControlName="email" >
</mat-form-field>
<button mat-flat-button (click)="onEdit()">Save</button>
</form>
TS
import {Component, Inject, OnInit } from '@angular/core';
import {
FormBuilder,
FormControl,
FormGroup,
Validators,
} from '@angular/forms';
import { IContact } from 'src/app/models/app.models';
import { CustomersService } from 'src/app/services/customers.service';
@Component({
selector: 'atd-edit-customer',
templateUrl: './edit-customer.component.html',
styleUrls: ['./edit-customer.component.scss'],
})
export class EditCustomerComponent implements OnInit {
public editForm: FormGroup;
public someContact: IContact;
constructor(@Inject(MAT_DIALOG_DATA) public data: IContact,
private fb: FormBuilder,
public customersService: CustomersService,
) {}
public ngOnInit(): void {
this.editForm = this.fb.group({
name: [null],
email: [null,[Validators.email],
});
}
public onEdit(): void {
this.someContact = this.editForm.value;
this.someContact.EMailAddresses= [];
this.someContact.EMailAddresses.push(this.editForm.value.email); <========
this.customersService.updateContact(this.someContact);
}
}
JSON looks like this:
export interface IContact {
id: string;
name: string
emailId: string[];
}
Now the issue is:
- When i hit the SAVE button without making any changes in the
emailinput field, The PUT operation is not happening and i am getting this response:
- But if a make some changes in the
emailinput field and hit the SAVE button, The PUT operation works fine.
I am pushing email like this:
this.someContact.EMailAddresses= [];
this.someContact.EMailAddresses.push(this.editForm.value.email);
What's wrong with the code ??

this.editForm.value.emailId inthis.someContact.EMailAddressesarray?emaili/p field, even i didn't make any changes also it shouldpush.emailthenapicall is successful, If not getting error as shown in the given image.