Search code examples
angularangular-ngmodel

Angular 4 - [(ngModel)] doesn't update in production site


I work on an Angular 4 app. I have a modal where I enter a supplier info and create one. I have a select box for the city.

  <select class="custom-select form-control" [(ngModel)]="newSupplier.city">
       <option *ngFor="let city of cities" [ngValue]="city">{{city.name}}</option>
  </select>

When I run the app in my local machine, everything works fine. When I select a city, the newSupplier variable is updated. But when I deploy the app to heroku, the app works fine but when I select the city, newSupplier variable is not updated. PS: I have other attributes in newSupplier which I enter using input such as:

<input class="form-control" type="text" [(ngModel)]="newSupplier.name">

This works both in my local and when I deploy.

I really don't know where this problem comes from. Thanks for helping.


Solution

  • Hello don't you need the reference too ?

    <input #name="ngModel" class="form-control" type="text" [(ngModel)]="newSupplier.name">
    

    Another possibility could be to add a (change) event handler