Click event not working within a form modal

After creating a simple button to open a modal, I encountered an issue with another button inside the modal. The "Close" button works fine and triggers the "closeLogin()" function, but the button within the login form that is supposed to launch a "doTestme()" function never seems to be triggered. Here is the code snippet for reference:

The button that correctly opens the modal:

<script id="templates/home.html" type="text/ng-template">
  <ion-view view-title="Welcome">
    <ion-content class="padding">
      <button type="button" class="button" ng-click="login()">Log-in Test, click on the beer!</button>
    </ion-content>
  </ion-view>
</script>

The controller "MainCtrl" managing the $scope:

  .controller('MainCtrl', function($scope, $ionicSideMenuDelegate, $ionicModal, $timeout) {
  $scope.loginData = {};

  // Create the login modal
  $ionicModal.fromTemplateUrl('templates/login.html', {
    scope: $scope
  }).then(function(modal) {
    $scope.modal = modal;
  });

  // Close the login modal
  $scope.closeLogin = function() {
    $scope.modal.hide();
  };

  // Open the login modal
  $scope.login = function() {
    $scope.modal.show();
  };

  $scope.doTestme = function() {
    alert("test ok");
  };

The modal that successfully pops out:

<script id="templates/login.html" type="text/ng-template">
<ion-modal-view>
  <ion-header-bar>
    <h1 class="title">Login</h1>
    <div class="buttons">
      <button class="button button-clear" ng-click="closeLogin()">Close</button>
    </div>
  </ion-header-bar>
  <ion-content>
    <form ng-submit="doLogin()">
      <div class="list">
    <label class="item item-input">
      <span class="input-label">Username</span>
      <input type="text" ng-model="loginData.username">
    </label>
    <label class="item item-input">
      <span class="input-label">Password</span>
      <input type="password" ng-model="loginData.password" style="-webkit-flex: 1 0 100px;"><button type="button" ng-click="doTestme()" class="button button-icon ion-beer" style="font-size:35px;"></button>
    </label>
    <label class="item">
      <button class="button button-block button-positive" type="submit">Log in</button>
    </label>
  </div>
</form>
  </ion-content>
</ion-modal-view>
</script>

It appears that the ng-click event is not being watched or triggered. There are no errors in the console, making it difficult to debug. Any insights on how to resolve this issue?

You can view the CodePen here: http://codepen.io/anon/pen/jEpNGB

Answer №1

Avoid using buttons within labels as it may cause functionality issues. Simply replace the container from <label> to <div>

<div class="item item-input">
          <span class="input-label">Password</span>
          <input type="password" ng-model="loginData.password" style="-webkit-flex: 1 0 100px;">
           <button type="button" ng-click="doTestme()" class="button button-icon ion-beer" style="font-size:35px;"></button>
        </div>

To see this in action, visit this codepen link

Answer №2

Initially, I attempted two different solutions:

  1. Modifying the function to "doAlert()"
  2. Switching the button to a regular link "test"

At first, it seemed to work! However, shortly afterwards, the link stopped triggering the alert box.

I only tested this on CodePen. Please try it elsewhere and provide feedback.

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

ng-click not functioning within ng-repeat inside a specified scope

Attempting to compile a list of books with the potential for comments, I am seeking the ability to click on a comments link (if comments are present) and view the corresponding list of comments. I have learned that each <li> creates its own scope. T ...

Implementing a callback in React/Redux: A step-by-step guide

I am working on a function that I want to move to a separate file. The issue is that this function involves making a request that can take some time to complete. My goal is to relocate the function to another file and only proceed with further actions once ...

The error "Unable to load Stylesheet" occurred in a Node.js/Express Application

I've been attempting to include a stylesheet in my webpage using Express, but for some unknown reason, it is not working as expected. When I directly visit the CSS file in the browser, everything appears to be fine, so it seems like there might be an ...

Observing data within an AngularJS service

I am currently working with a service called sharedData and a controller named HostController. My goal is to have the HostController monitor the saveDataObj variable within the sharedData service, and then update the value of host.dataOut, which will be re ...

Sending information to a PHP script using Ajax

I am working on a project that involves input fields sending data to a PHP page for processing, and then displaying the results without reloading the page. However, I have encountered an issue where no data seems to be passed through. Below is my current s ...

comparative analysis: nextjs getServerSideProps vs direct API calls

Trying to grasp the fundamental distinction between getServerSideProps and utilizing useSWR directly within the page component. If I implement the following code snippet in getServerSideProps: export const getServerSideProps = async () => { try { ...

How can we display the numbers between two given numbers in Ionic 2 while incrementing or decrementing the value?

I am developing a geolocation-based speed tracking feature that displays the speed on the screen. However, I have encountered a problem where there is a significant gap between the previous and current speed values, and I would like to implement a transiti ...

What is the best way to connect a line from the edge of the circle's outermost arc?

I am attempting to create a label line that extends from the outermost point of the circle, similar to what is shown in this image. https://i.sstatic.net/OqC0p.png var svg = d3.select("body") .append("svg") .append("g") svg.append("g") .attr("cl ...

Best practices for refreshing the HTML5 offline application cache

My website utilizes offline caching, and I have set up the following event handler to manage updates: applicationCache.addEventListener('updateready', function () { if (window.applicationCache.status == window.applicationCach ...

Tips for positioning the overlay to match the icon list when hovering- JavaScript/Cascading Style Sheets (CSS)

My challenge involves a list of <li>'s accompanied by an icon that, when hovered over, displays an overlay containing information about the 'test'. The setup looks something like this: test1 test2 test3 and so forth.... Here' ...

Inquiries prior to projecting rays

As I delve into the world of Interaction with Three.js, several questions arise in my mind. 1) Can you shed some light on what exactly Viewport Coordinates are? 2) In what ways do they differ from client Coordinates? 3) How did we come up with this form ...

Utilize the mockService within a controller that is initialized through a directive

I am looking to perform unit testing (karma) on a directive that includes a controller with injected services. Below is the code snippet: angular .module('webkr') .directive('userChangePassword', userChangePassword) .direc ...

Tips for including an additional class in an element

I have an image tag with the "kiwi" class, and another class that makes it spin. I want to toggle this second class (called 'elem') when clicking on the play button of my music player. Here is the image tag with the class: <img src="./im ...

Guide to testing nested directives in Angular 1.x: Mocking techniques for unit testing

Hey, I am having an issue with mocking my directive. Here is the code snippet: <dir-one data="data"> <div ng-repeat="e in data"> <div ng-repeat="e2 in e"> <dir-two prop="e2.some" prop2="e2.some"> <!-- I want to mock this ...

Exploring Vue.js: Enhancing Button Functionality with Select Range

I have a question regarding button selection in a v-for loop. I need to allow users to select options from A to C, as shown in the graphic. Additionally, users should be able to press another button like D. <menu-item v-for="(item, index) in me ...

What is the best way to personalize the collector for each individual?

Currently, I have a bot that is capable of collecting messages and replying if it detects a specific word. However, I am facing an issue where the bot keeps creating new collectors every time someone types the word tekong. As a result, the bot ends up resp ...

Utilizing *ngIf for Showing Elements Once Data is Completely Loaded

While working on my Angular 2 app, I encountered an issue with the pagination UI loading before the data arrives. This causes a visual glitch where the pagination components initially appear at the top of the page and then shift to the bottom once the data ...

"Learn the technique of displaying or concealing a row in a ListView with the help of

I'm currently utilizing an Asp.net Listview for displaying data in a "grid" format. Below is the code snippet: <asp:ListView ID="lvDmr" runat="server" DataSourceID="dsDmr" DataKeyNames="id"> <ItemTemplate> &l ...

Tips for retrieving all JavaScript source links from a website URL during page download

Is there a way to determine if a website is using a specific online JavaScript source, such as fontawesome? Some sources may only become apparent once they are actually loaded, rather than being visible in the website's source HTML. I attempted to us ...

What is preventing the click event on this dynamically generated checkbox using jQuery?

Check out the jsFiddle Currently, I am utilizing a jQuery plugin that enables users to draw boxes within a designated area. Using jQuery, I have incorporated a checkbox (alongside a dropdown list) into the box that appears when the user releases the mouse ...