Call JS method in another file on click event in HTML

I am out of steam and could really use some help. Eventually I will want to send JSON requests and responses on click events in my app, but right now I am trying to console.log("Button Pressed ID: " + id) in a JS method when my button is clicked, and my JS method is not getting called onClick.

I am seeing this reference error: ReferenceError: Can’t find variable: loginPressed

loginPressed(id) {
console.log("Button Pressed ID: " + id)


      <div class="spacer" style="height: 40px;"></div>
      <script type="text/javascript" src="src/pages/login/login.ts"></script>
    <ion-list id="login-list2">
        <label class="item item-input item-floating-label" id="login-input1">
          <span class="input-label">Email</span>
          <input type="email" placeholder="Email">
        <label class="item item-input item-floating-label" id="login-input2">
          <span class="input-label">Password</span>
          <input type="password" placeholder="Password">
        **<button id="loginButton" onclick="loginPressed(">Log in!</button>**

<ion-content padding>


Any help or examples you know of that use the ionic framework and JSON as well as using the JS files heavily would be really awesome. I can’t find the right stuff online.

Thanks so much,

This is extremely unidiomatic. You should not have <script> tags referencing controller pages; let the Angular compiler do its work and simply define loginPressed in the component which references this template.

Thanks, @rapropos. This was my best compilation of different stack overflow articles and such. I am not able to find a great example online of something that uses a buttonID to call a JS method. Do you know of any such resource? I think one or two examples would help me grasp the concept.

Thanks so much.

You are using Angular, right? Either ionic-angular or @ionic/angular?

Yes, I’m using ionic-angular, with ionic version 4.0.6

Then I would suggest emulating the ionic-conference-app login feature.