title: Angular 2 get Input element value
body: <p>how to  get html element value using ionic 2</p>
  
  <p>Below my html code</p>
  
  <pre><code> &lt;div class="messagesholder" *ngFor="let chat of chatval | orderby:'[date]'" &gt;
     &lt;div *ngIf="chat.sender == currentuser || chat.receiver == currentuser"&gt;
      &lt;div  *ngIf="chat.date" style="text-align: center;" &gt;
             &lt;p style="font-size:9px;" id="amount" #amount&gt;{{chat.date | amDateFormat:'LL'}}&lt;/p&gt;
             &lt;input #myname [ngModel]="range" (ngModelChange)="saverange($event)"/&gt;
           &lt;input #myname type="text" value={{chat.date}}&gt;
      &lt;/div&gt;
     &lt;/div&gt;
     &lt;div class="message" *ngIf="chat.sender == currentuser || chat.receiver == currentuser" [ngClass]="{'me': currentuser == chat.sender}"&gt;
            &lt;div class='image' *ngIf="chat.path" &gt;
              &lt;img *ngIf="chat.path" [src]="chat.path"/&gt;&lt;br&gt;
              &lt;span *ngIf="chat.path_text"&gt;{{chat.path_text}}&lt;/span&gt;
              &lt;span style="font-size:9px;"&gt;{{chat.date | amDateFormat:'hh:mmA'}}&lt;/span&gt;
            &lt;/div&gt; 
             &lt;div *ngIf="chat.message_text"&gt;
             &lt;span&gt;{{chat.message_text}}&lt;/span&gt;
             &lt;span style="font-size:9px;"&gt;{{chat.date | amDateFormat:'hh:mmA'}}&lt;/span&gt;
             &lt;/div&gt;
      &lt;/div&gt;
  </code></pre>
  
  <p></p>
  
  <p>Below my ts file</p>
  
  <pre><code>import { Component,Inject,ViewChild,ElementRef,AfterViewInit} from '@angular/core';
  
  export class ChatPage implements AfterViewInit {
    @ViewChild('myname') input:ElementRef; 
    constructor(public modalCtrl: ModalController,public navCtrl: NavController) {}
     ngAfterViewInit() {
      console.log(this.input.nativeElement.value);
      }
    }
  </code></pre>
  
  <p>Same date values are repeated.I want same date values are not repeated.</p>
  
  <p>Because I will check two variable.</p>
  
  <p>so I need chat.date value.because i binded the value of input.But i cannot get the value of input element.</p>
  
  <p>i am getting this error</p>
  
  <p>Cannot read property 'nativeElement' of undefined</p>
  
  <p>How to fix this issue.or any other way to find slutions.</p>
  
  <p>Thanks</p>