I am using an expansion panel which I got from here. I am using a loop to create each row and I would like for when the panel is expanded it shows the data from the current row to be edited. I am new to angular and what I have works, it updates the database. But what I have does not seems like the best solution because when the form opens it opens with the selected object data but as a place holder then the data becomes the label for the Textbox and the Textbox becomes empty. Is there a way to bind the current value to the Textbox value and not the placeholder and if I focus on the Textbox it keeps the text for me to edit.
Html:
<tr *ngFor="let search of searches">
<mat-expansion-panel (opened)="panelOpenState2 = true" (closed)="panelOpenState2 = false">
<mat-expansion-panel-header>
<td><span class="badge">3</span></td>
<td>{{ search.name }}</td>
<td><button color="warn" (click)="deleteSearch(search._id)" class="btn btn-primary float-right">Del</button></td>
</mat-expansion-panel-header>
<td>
<mat-form-field>
<input matInput placeholder="{{ search.name }}" [(ngModel)]="inputValue" name="name" type="text" class="form-control rounded-0" required>
</mat-form-field>
</td>
<td><button (click)="updateSearch(search._id, inputValue)" class="btn btn-primary float-right">Edit</button></td>
</mat-expansion-panel>
</tr>
TypeScript Function:
updateSearch(id, name) {
this.searchService.updateSearch(id,name,'dd')
.subscribe(
res => {
console.log(name+ 'fjjf')
console.log(res)
this.fetchSearches();
},
err => console.log(err)
)
}