0

This is my html:

<form class="row" (ngSubmit)="generatePdfFromOverview()" #generatePdfForm="ngForm">
    <select id="selectedSortOnItem" required [(ngModel)]="generatePdfForm.selectedSortOnItem"
        name="selectedSortOnItem" #selectedSortOnItem="ngModel">
            <option *ngFor="let sortOnItem of sortOnItems" [value]="sortOnItem">{{sortOnItem}}</option>
    </select>
    <button type="submit" class="btn btn-primary">Generate it!</button>
</form>

The values are showing fine in the view.

However the value is not updated in the .ts file when I select another one. Tried numerous things. Followed the example in the Angular docs but does not seem to work..

Gonçalo Peres
  • 11,752
  • 3
  • 54
  • 83
stijn.aerts
  • 6,026
  • 5
  • 30
  • 46

2 Answers2

0

Although it completely depends on your generatePdfFromOverview method, there are a few things that you can do to fix this issue:

Pass generatePdfForm to the generatePdfFromOverview as an argument and then use the value property on it to get the value of the form.

<form 
  class="row" 
  (ngSubmit)="generatePdfFromOverview(generatePdfForm)" 
  #generatePdfForm="ngForm">

And then in your Component Class:

generatePdfFromOverview(generatePdfForm) {
  console.log('Form Value: ', generatePdfForm.value);
}

This value is going to have a selectedSortOnItem property on it which is what you're looking for.

Here's a Sample StackBlitz for your ref.

SiddAjmera
  • 38,129
  • 5
  • 72
  • 110
0

Turns out this was related to an issue of https://materializecss.com/

The javascript from Materialize was causing issues with the select functionality.

Upgrading to 1.0.0 resolved the issue.

stijn.aerts
  • 6,026
  • 5
  • 30
  • 46