当用户单击“保存”按钮时,我正在尝试提交html页面的单个区域。 html页面由许多可以编辑的任务组成,当用户单击“保存”按钮时,我希望将单个任务提交给服务器,即不是将所有任务都提交给服务器。做这个的最好方式是什么。下面是我的代码:-
HTML:-
but got array with shape (43,)
Task.component.ts:-
<mat-accordion multi="true">
<div class="task-element" *ngFor="let task of selectedDayTasks">
<div class="expansion-panel">
<mat-expansion-panel>
<mat-expansion-panel-header>
<mat-form-field class="title-box">
<input matInput
value="{{ task.title }}">
</mat-form-field>
<!--{{ task.title }}-->
</mat-expansion-panel-header>
<mat-form-field class="description-box">
<textarea matInput value="[(task.description)]"></textarea>
</mat-form-field>
<!--<p>{{ task.description }}</p>-->
<mat-action-row>
<button mat-button color="warn" (click)="onSave(task._id, task.title, task.description, task.complete, task.day)">SAVE</button>
</mat-action-row>
</mat-expansion-panel>
</div>
<div class="done-button">
<button class="green-btn" *ngIf="task.complete" (click)="taskStateChange(task._id)" mat-fab>YES</button>
<button *ngIf="!task.complete" (click)="taskStateChange(task._id)" color="warn" mat-fab>NO</button>
</div>
</div>
</mat-accordion>
答案 0 :(得分:0)
我已经解决了,我需要使用[(ngModel)],即-
<input matInput [(ngModel)] = {{task.title}}">