Answer the question
In order to leave comments, you need to log in
Why does the Post data update method not work?
When I click the "Edit" button, information about a specific post goes into the input fields, but when I click the "updatePost" button to update this data, the information is updated for all posts except for the one where I want to update the information. Help me solve this problem and understand what I'm doing wrong
Edit component template:
<form [formGroup]="angFormEd" novalidate>
<div class="form-group">
<label class="col-md-4">Picture Title</label>
<input type="text" class="form-control" formControlName="titleEd" minlength="1" #titleEd
[(ngModel)]="edData.title"/>
</div>
<div class="form-group">
<label class="col-md-4">Picture Address (url)</label>
<input type="url" class="form-control" formControlName="urlEd" #urlEd pattern="https?://.+"
title="Include http://" [(ngModel)]="edData.url"/>
</div>
</div>
<div class="form-group but-group">
<button (click)="updatePost(titleEd.value, urlEd.value, edData.id); angFormEd.reset(titleEd.value, urlEd.value)"
class="btn btn-primary">Update Post
</button>
</div>
</form>
</div>
</div>
editPost(picId: Picture[]): void {
this.edData = picId;
}
updatePost(title: string, url: string, id:number): void {
const update: Picture[] = this.collection.map((p)=>{
p.id = id;
p.title = title;
p.url = url
});
}
Answer the question
In order to leave comments, you need to log in
updatePost(title: string, url: string, id:number): void {
const update: Picture[] = this.collection.map((p)=>{
p.id = id;
p.title = title;
p.url = url
});
}
editPost(picId: Picture[]): void {
this.edData = picId;
}
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question