Olli
Olli

Reputation: 532

Get input form Ionic 2, Typescript, Angular2

New to building with Angular 2 and Typescript, I'm trying to do something I do very frequently otherwise which is collect information from input form which in this case is the email.

Now I couldn't use var x = document.getElementById("email").value; because Typescript gave an error so I went and used this instead var x = (<HTMLInputElement>document.getElementById("email")).value; but now I get undefined, my HTML is as such:

 <div class="padding" style="text-align:center;">
    <ion-list>

      <ion-item>
        <ion-label floating>Email</ion-label>
        <ion-input type="text" id="email"></ion-input>
      </ion-item>

      <ion-item>
        <ion-label floating>Password</ion-label>
        <ion-input type="password"></ion-input>
      </ion-item>

    </ion-list>
 </div>

Anyone know why?

Upvotes: 1

Views: 187

Answers (1)

Jorawar Singh
Jorawar Singh

Reputation: 7621

You should use view child to get element instead of pure js. E.g

@(ViewChild) yourElement;

And in your html instead of id pass #yourElement and you should be able to access the value of that element.

Upvotes: 1

Related Questions