#angular #typescript
Вопрос:
Моя проблема в том, что я не могу достичь значения моих динамических входных данных.
lt;form [formGroup]="titelForm"gt; lt;table mat-table [dataSource]="titelSource" #titelTable gt; lt;ng-container matColumnDef="edit"gt; lt;th mat-header-cell *matHeaderCellDefgt; Speichern lt;mat-icon color="primary"gt; save lt;/mat-icongt; lt;/thgt; lt;td mat-cell *matCellDef="let titel; let i = index; "gt; lt;button mat-mini-fab color="primary" (click)="saveRow(titel.titelvorschlagId,titel.bezeichnung)" gt; lt;mat-icon color="white"gt; save lt;/mat-icongt; lt;/buttongt; //Heres where im trying to give the current value to my function lt;/tdgt; lt;/ng-containergt; lt;ng-container matColumnDef="delete"gt; lt;th mat-header-cell *matHeaderCellDefgt; Löschen lt;mat-icon color="warn"gt; clear lt;/mat-icongt; lt;/thgt; lt;td mat-cell *matCellDef="let titel; let i = index"gt; lt;button mat-mini-fab color="warn" (click)="confirmDelete(titel.bezeichnung,i)" gt; lt;mat-icon color="white"gt; clear lt;/mat-icongt; lt;/buttongt; lt;/tdgt; lt;/ng-containergt; lt;ng-container matColumnDef="bezeichnung"gt; lt;th mat-header-cell *matHeaderCellDefgt; Bezeichnung lt;/thgt; lt;td mat-cell *matCellDef="let titel; let i = index;"gt; lt;ng-containergt; lt;mat-form-field appearance="standard"gt; lt;input matInput type="text" [value]='titel.bezeichnung' formArrayName="bezeichnung" name="titel"gt; //thats where the value comes from lt;/mat-form-fieldgt; lt;/ng-containergt; lt;/ng-containergt; lt;tr mat-header-row *matHeaderRowDef="displayedColumns"gt;lt;/trgt; lt;tr mat-row *matRowDef="let row; columns: displayedColumns;"gt;lt;/trgt; lt;/tablegt; lt;/formgt;
Мои начальные значения поступают из моей базы данных. Текущая проблема заключается в том, что функция просто получает значение из моей базы данных, поэтому, если я изменю его во входных данных, это не изменит значение в моей функции.
Моя функция
saveRow(id:string, bezeichnung:string){ console.log(id); if(id != undefined) { this.table.renderRows(); let postObject = { titelvorschlagId: id, bezeichnung: bezeichnung, //Should be current value not the old value from my database }; console.log("PUT"); console.log(postObject); } if(id == undefined) { this.table.renderRows(); let postObject = { bezeichnung: bezeichnung, //Should be current value not the old value from my database }; console.log("POST"); console.log(postObject); } }
Поэтому я знаю,что мне нужно изменить saveRow(titel.titelvorschlagId, ЭТО ПРЯМО ЗДЕСЬ)). Но я не знаю, как я мог бы вложить в это текущее значение. Уже пробовал что-то вроде i.value (для index.value), но это также не работает.