Issues with parameters arose following a function call from an Ionic modal

In my Ionic+Angular application, I have implemented a view with a simple button that opens a modal. The modal template is displayed correctly after clicking the button:

<ion-modal-view>
  <ion-header-bar>
    <h1 class="title">Popular tags</h1>
    <div class="buttons">
      <button class="button button-clear button-stable" ng-click="closePopularForm()">Close</button>
    </div>
  </ion-header-bar>
  <ion-content>
      <div class="list">
        <div class="item-divider text-center">
          Select a tag to follow.
        </div>
        <label class="item">
        <button class="button button-balanced" ng-click="addPopularTag('china')">China</button>
            <button class="button button-balanced" ng-click="addPopularTag('uk')">United Kingdom</button>
            <button class="button button-balanced" ng-click="addPopularTag('us')">United States</button>
        </label>
      </div>
  </ion-content>
</ion-modal-view> 

Although the modal has three buttons, each invoking the same function with different parameters, when clicked, the function addPopularTag is always called with the parameter of the first button (which is 'China' in this scenario). Even though the buttons are rendered correctly with distinct parameters.

The controller containing the functions is as follows:

app.controller('HomeCtrl', function($scope, $ionicSideMenuDelegate, $ionicModal) {

  $ionicModal.fromTemplateUrl('add-popular.html', { scope: $scope }).then(function(modal) {
        $scope.modalPopular = modal;
    });

    $scope.closePopularForm = function() {
        $scope.modalPopular.hide();
    };

    $scope.openPopularForm = function() {
        $scope.modalPopular.show();
    };

    $scope.addPopularTag = function(poptag) {
        console.log(poptag);
        console.log('pop form submitted '+poptag);
    };  
});

To reproduce the issue, you can check out the Codepen here. The problem can be observed in the console log.

Answer №1

Modify

<label class="item">
  <button class="button button-balanced" ng-click="addPopularTag('china')">China</button>
  <button class="button button-balanced" ng-click="addPopularTag('uk')">United Kingdom</button>
  <button class="button button-balanced" ng-click="addPopularTag('us')">United States</button>
</label>

to

<button class="button button-balanced" ng-click="addPopularTag('china')">China</button>
<button class="button button-balanced" ng-click="addPopularTag('uk')">United Kingdom</button>
<button class="button button-balanced" ng-click="addPopularTag('us')">United States</button>

I'm not sure about the functionality of the label element though.

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

Issue with implementing OpenLayers map in Vue-CLI 3 - troubleshooting needed

I recently incorporated the ol package into my vue-cli project by running npm install ol Unfortunately, despite adding the package, the map is not loading. No errors are displayed and all I see is an empty div in the source result. Here is a snippet o ...

Discovering the optimum route within a 2D array given specific limitations using Dynamic Programming

Hey, I have a query related to dynamic programming (dp) that goes like this: Input: A 2D array of numbers Output: The maximum sum of a path from (0,0) to (n-1,n-1) with the following conditions: You can only move down and right i.e. from (A[i-1][j]) t ...

To properly render an HTML file before loading a JavaScript file, express.static fails to serve the HTML file

Within my server.js file, the following code is present: var path = require('path'); var express = require('express'); var app = express(); var htmlRoutes = require('./app/routing/routes.js')(app, path, express); As for my r ...

Issue with date comparison operator logic

Here's a simple JavaScript function I have: function checkTime() { var current = new Date(); var target = new Date('April 10, 2017 12:11:00'); if (current < target) { $('#modalnew').modal('show'); } els ...

Facing issues with Javascript coding quiz calculations

I've been working on a quiz that is supposed to tally the correct and incorrect answers. However, no matter how many correct answers I input, both arrays always show a result of 0. It seems like there must be an issue in the evaluate function at the e ...

Switching between Custom tooltips and default tooltips in Chart.js and Angular

I need to show a tooltip based on certain conditions options: { tooltips: if (tooltipCondition === true) { { mode: 'index', position: 'nearest' } } else { { enabled: false, custom: function (tooltipMo ...

Comparing a stored array in Mongo against a native JavaScript array with identical length and values results in a failed deep assert comparison

In my mongoose ORM, I have a field in mongo defined as: state: {type: [Number], required: true } When I check a sample document in the mongo console, the state appears as: state: [ 1, 1, 1 ] Everything seems to be in order so far. However, when I try t ...

Organizing list items with interactive buttons on an Ionic grid

Struggling to format a list containing a label and two buttons in each item. Need assistance with the styling. Below is the code snippet and an image illustrating the desired outcome. <ion-content> <ion-list> <ion-item> <ion-labe ...

Implementing a directive in the form of the md-dialog

Hello everyone, I am facing a challenge in trying to incorporate code for a dialog within a directive. To elaborate: $mdDialog.show({ ..... template: '<my-directive></my-directive>', ..... }) And naturally, "my directive" would be ...

Why is it necessary for me to tap the button twice in order to access the URL?

Can you help me figure out why my code is requiring two clicks to open a URL? This is the Angular Directive code I'm using: 'use strict'; angular.module('ui.components') .service('MoreDetailsService', function(){ r ...

Identify the visibility status of a mesh that may be obscured by an object

I am currently working on a project that involves a scene with an Object3D representing a globe and multiple mesh elements that represent points on the globe. To enable user interaction, I am using OrbitControls. In addition to this, I am attaching HTMLEle ...

Using NextJS to navigate user journey by mapping an array of values from Formik to

I really appreciate all the help I've received so far, but I'm facing an issue trying to map an object with an array within it to the router. Here is my current code: const initialValues = { region: query.region || 'all', campt ...

Configuring Angular 6+ Applications at Run Time

What is the most effective approach for loading environment-specific configuration at runtime in an Angular application? The Angular documentation suggests utilizing APP_INITIALIZER, but this may not be early enough in the loading process for configuring i ...

What is the method for assigning a value to a JSON object using data from another JSON object?

I am faced with the task of setting the seqNo property in one JSON object, b, based on the id from another JSON object, a. How can I achieve this? var a = [{id: "Make", seqNo: 4}, {id: "Model", seqNo: 1}, {id: "XModel", seqNo: 2 ...

Experimenting with two iterations of the json-schema to ensure compatibility across different versions

I manage a repository that stores versioned json-schemas, meaning I may have multiple revisions for each type of schema (v1, v2, v3, etc). My goal is to test these schemas for backwards compatibility, ensuring that any data valid for a v1 schema will also ...

Transforming sound data into a file format for submission to the backend system (without the need to store it on the

UPDATE: I found a few minor errors in this post, which have been fixed and resolved some of the issues. The other half of the problem is addressed in the accepted answer. ... I am currently capturing microphone audio on the client side (using Nuxt/Vue) a ...

changing font size on a mobile-friendly site using javascript

Currently, I am designing a responsive webpage utilizing Bootstrap framework. Situated in the center of the screen is a text that reads: <p id="entershop" ><a class=no-deco href="shop.html">enter shop</a></p> Within the Bootstra ...

Navigating a collection of objects after a button is clicked

My current library project involves looping through an array of objects to display them on a grid based on input values. Here is the code snippet for my loop: const addBook = (ev) => { ev.preventDefault(); let myLibrary = []; let bookIn ...

Pedaling back and forth along a sequence

Is there a way to implement forward and backward buttons for a clickable list without using arrays, as the list will be expanding over time? I have already achieved changing color of the listed items to red, but need a solution to navigate through the list ...

Restrict the height of posts created in the summernote editor

My goal is to create a structured page application using summernote. When using summernote, a div with contenteditable=true is appended to the body to allow users to add content. However, I want to set a fixed height for this div so that users can only ent ...