1

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?

1 Answer 1

1

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.

Sign up to request clarification or add additional context in comments.

1 Comment

Not very well explained, however worked once I also read through this learnangular2.com/viewChild

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.