UPDATE: I'm having trouble with my code not updating the selected value with the new one entered in the input field "newVb". The error message says 'this.newVarde' is undefined when it reaches the line 'this.selectedVarde = this.newVarde'. Instead of updating the selected value, it's adding a new one. I'm stuck on why this is happening...
.ts
export class RightMenuComponent implements OnInit {
public selectedVarde: this.selectedVarde;
public newVarde: Varde;
constructor(private _vardeService: VardeService) {
}
updateVarde() {
var beskrivning = this.selectedVarde;
var newVarde = (<HTMLInputElement>document.getElementById('newVb')).value;
this.varde = {
Beskrivning: newVarde,
}
this.selectedVarde = this.newVarde;
this._vardeService.updateVarde(this.varde).subscribe(() => { console.log("Lyckat") });
}
And then my .html:
<label for="updateVarde">T:Värdet som du vill uppdatera</label>
<select [(ngModel)]="selectedVarde" id="selectedVarde" name="updateVarde" class="form-control" required >
<option *ngFor="let varde of allaVarden" [ngValue]="varde">{{varde.beskrivning}}</option>
</select>
<button type="button" class="btn btn-primary" (click)="updateVarde()" style="margin-left:4%;" data-toggle="modal" data-target="#vardeModal" data-dismiss="modal">T:Redigera valt värde</button>
<label for="beskrivning">T:Nytt värde: </label>
<input class="input" style="width:10%;" id="newVb" type="text">
Appreciative of any insights on what might be causing the issue in the code