Reputation: 113
Trying to make a put Request to update the JSON in Angular 8. This is the error which I am getting:
The HTML file :
<td>
<a>
<button *ngIf="enableEdit && enableEditIndex == i" (click)="enableEdit=false; cancel()" class="btn page-secondary-action-btn" >Cancel</button>
<button *ngIf="enableEdit && enableEditIndex == i" id="saveBtn" class="btn page-primary-action-btn" (click)="saveSegment()" type="submit">Save</button>
<i class="material-icons" *ngIf="i != enableEditIndex || enableEditIndex == null" (click)="enableEditMethod($event, i)" style="font-weight:bold; font-style:inherit ;color: green;">
edit
</i>
</a>
</td>
Corresponding TS file :
saveSegment(data: blog) {
console.log('editable data', data);
this.blog.saveBlog(data).subscribe((Response) => {
this.toastr.info('Updated successfully', 'blogs.id');
this.route.navigate(['/admin/blogger']);
}, (err) => {
console.log(err);
});
}
And the Service file :
saveBlog(data: blog) {
const body = {
id: data.id,
name: data.name,
status: data.status,
active: data.active,
modifiedAt: data.modifiedAt,
};
return this.http.put(this.mainUrl + '/blog/' + data.id , body);
}
Here I am trying to edit and save the data to my web api, but the process is not working and hence getting the error as shown like in the image.
Upvotes: 0
Views: 972
Reputation: 3386
(click)="saveSegment(data)"
you have not pass the argument in the function
Like this:
<li *ngFor="let data of list">
<button (click)="saveSegment(data)"> Click </button>
</li>
Upvotes: 1
Reputation: 1312
Data param is missing when you call saveSegment() from your html, just add it :
...
<button *ngIf="enableEdit && enableEditIndex == i" id="saveBtn" class="btn page-primary-action-btn" (click)="saveSegment(data)" type="submit">Save</button>
...
Upvotes: 0