title: Angular 2 way number binding converting to string from input
body: <p>Any time I enter a number into an input that is 2 way bound to my object the value is converted to a string.<br>
  <strong>How can I force it or convert it to be a number?</strong></p>
  
  <p>It seems like it should be very simple and yet I have struggled to find an elegant solution.</p>
  
  <p>I saw this solution of using a function to convert it but I don't see how that would work for 2 way data binding.<br>
  <a href="https://stackoverflow.com/questions/45860349/convert-string-to-number-angular-2-one-way-binding">convert string to number angular 2 one way binding</a></p>
  
  <pre><code>          &lt;div class="row"&gt; 
              &lt;mat-form-field class="custom-control"&gt;
                &lt;input type="number" matInput class="custom-control" [(ngModel)]="mpv.baseFare" required placeholder="Base Fare"&gt;
              &lt;/mat-form-field&gt;
            &lt;/div&gt;
            &lt;div class="row"&gt; 
              &lt;mat-form-field class="custom-control"&gt;
                &lt;input type="number" matInput class="custom-control" [(ngModel)]="mpv.mileageRate" required placeholder="Mileage Rate"&gt;
              &lt;/mat-form-field&gt;
            &lt;/div&gt;
  </code></pre>
  
  <p>mpv is an object of class VehicleType I have my VehicleType class set up as follows.  The number types are completely ignored, I guess because it is at run time so just non typed javascript.</p>
  
  <pre><code> export class VehicleType {
      baseFare: number;
      mileageRate: number;
  }
  </code></pre>
  
  <p>UPDATE - CURRENT HACKY SOLUTION:</p>
  
  <pre><code>onSave(vehicleType: VehicleType) {
  // Hack to convert string to number
  vehicleType.bags = +vehicleType.bags;
  vehicleType.baseFare = +vehicleType.baseFare;
  vehicleType.mileageRate = +vehicleType.mileageRate;
  vehicleType.passengers = +vehicleType.passengers;
  this.vehicleTypeService.updateVehicleType(vehicleType.id, vehicleType).subscribe(result =&gt; {
  </code></pre>