title: How do I calculate age from birth date in Angular 2 using TypeScript
body: <p>I have 2 textboxes. One textbox will accept birth date from the user and based on birth date I want to calculate and display their age in another textbox.</p>
  
  <p>Here's my component class</p>
  
  <p><strong>Student.component.html</strong></p>
  
  <pre><code>&lt;div class="row"&gt;
  &lt;div class="input-field col m2"&gt;
      &lt;input type="date" id="txtdate"&gt;
  &lt;/div&gt;
  &lt;div class="input-field col m4"&gt;
      &lt;input type="number" id="age"&gt;
  &lt;/div&gt;
  </code></pre>
  
  <p></p>
  
  <p><strong>student.component.ts</strong></p>
  
  <pre><code> import { Component, OnInit } from '@angular/core';
  
  @Component( {
   selector: 'stud',
   templateUrl: './student.component.html'
   })
   export class StudentComponent implements OnInit
  {
  
       constructor() { }
  
       ngOnInit() { }
  
  }
  function CalculateAge()
  {
       var birthdate = &lt;HTMLElement&gt;document.getElementById( "txtdate" );
       var dt = new Date();
       var today = dt.getDate();
  
  }
  </code></pre>
  
  <p>How do I calculate age from birth date?</p>