AngularJS ng-click function not functioning as expected when used within ng-repeat

The event.id is correctly displayed in the html text, but the function does not receive it properly. Even though it appears correctly in the source code, there seems to be an issue here.

<span ng-repeat="event in [{"id":"dxczhlyvmblc","name":"4 on 4 - Pickup","venuename":"Box Hill Aqualink","numspotsleft":"<strong>Spots now open<\/strong>","day":"28","dayname":"Wednesday"}]">
    <button ng-click="toggleModal('<% event.id %>')">More detail = <% event.id %></button>
</span>

https://i.sstatic.net/HYwpy.jpg

shopApp.controller('MainController', function($scope, $http, $q){
    $scope.toggleModal = function(eventId){
        console.log(eventId+" toggle");
    };})

Please note that I am using <% instead of {{ due to the templating engine being used.

Answer №1

Reasoning for not utilizing Angular templating expressions in view function arguments.

Update to:

ng-click="toggleModal(event.id)"

If you intend to pass the entire object, it may be easier to do so when passing it to a modal controller, for instance.

Answer №2

If you wish to transfer the event.id value to the function called toggleModal:

<button ng-click="toggleModal(event.id)">Click for More Details: <% event.id %></button>

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

Find all LI elements within UL containers that are not contained in a UL element with a specific class using jQuery

How can I select all elements from ul, excluding those with the class not-need? <ul> <li></li> <li></li> <li></li> <li></li> <li></li> </ul> <ul class='not ...

Error: The <Class> cannot be accessed until it has been initialized

I have a basic autoloader method that initializes and returns an instance of a class using require() The require statement includes some logic that requests information from a database and checks if the class exists in the filesystem. let elementClass = r ...

How can I store the status of checked and unchecked checkboxes in an array of objects using Angular 7?

I have a set of checkboxes with a parent-child structure, and their values are generated dynamically in a loop. When I click the submit button, I want to capture the selected or unselected values in the specified format (as shown in the commented output) ...

Animation effects compatible with iOS devices are professionally crafted using CSS

I just implemented a custom hamburger menu with animation using HTML, CSS, and JavaScript on my website. The animation works perfectly on Android devices but not on iOS. Any suggestions for fixing this issue? I attempted to add the Webkit prefix to each p ...

Align Headers to the Top Center in React Material-UI Datagrid

Is there a way to align the wrapped headers at the top-center using sx? I've tried the following code: const datagridSx = { '& .MuiDataGrid-columnHeaders': { height: 'unset !important', maxHeight: '168p ...

Preventing special characters in an input field using Angular

I am trying to ensure that an input field is not left blank and does not include any special characters. My current validation method looks like this: if (value === '' || !value.trim()) { this.invalidNameFeedback = 'This field cannot ...

Issue arises when trying to insert an image avatar onto a globe in three.js

I have successfully implemented a rotating 3D globe using three.js with the code provided below. HTML <canvas id="canvas"></canvas> JS let camera; let renderer; function main() { const canvas = document.querySelector('#ca ...

Eliminate the excess padding from the Material UI textbox

I've been struggling to eliminate the padding from a textbox, but I'm facing an issue with Material UI. Even after setting padding to 0 for all classes, the padding persists. Could someone provide guidance on how to successfully remove this pad ...

In Javascript, merge two arrays together in a specific format

Can we transform two arrays into a specific format so I can create my D3 graph? Here are the two arrays I have: date = ["sept,09 2015","sept, 10 2015","sept, 11 2015"] likes = [2,4,5] I need to convert them to this format: [{ date: '...', lik ...

Acquiring the asset within the controller

Having trouble accessing my service within the controller. This project was generated with the latest yeoman which handles template creation and file merging during build. Whenever I make changes, Angular stops working without displaying any errors in the ...

What is the best way to include an onClick event on a hyperlink enclosed within a string?

I am trying to wrap an anchor tag within a string. export function linkify(inputText) { const replacePattern = /(\b(https?|ftp):\/\/[-A-Z0-9+&#/%?=~_|!:,.;]*[-A-Z0-9+&#/%=~_|])/gim; if (replacePattern.test(inputText)) { input ...

Tips on assigning html actions/variables to a flask submit button

I am facing an issue with my Flask app where the form submission process takes a while for the backend to process. In order to prevent users from refreshing or resubmitting, I want to display a loading gif during this time. The current HTML code for my fl ...

A guide to converting variables into a JSON Object in Javascript

I am looking for a way to insert external variables into a JSON object. An example of what I want: var username = "zvincze"; And then, using that variable to inject it into a JSON object: var json = '{"username":"VARIABLE_GOES_HERE"}' var obj ...

Vue not displaying local images

I'm having trouble creating an image gallery with Vue.js because local images are not loading. I have the src attributes set in the data attribute and can only load images from external sources. For example: data() { return { imag ...

Experiencing an issue with excess right padding when utilizing Bootstrap 4.5 cards

I am attempting to implement this specific bootstrap 4.5 card layout in my react application, but I am encountering the following two problems: All three cards in the deck have an additional right padding of 44px. The card header is lacking a complete bor ...

Incorporate form checkboxes with the image's title preceding them within every individual div

Is there a way to dynamically add a form checkbox to each of these divs with incrementing id's? My current setup is as follows: <div class="img-wrap"> <img title="1" src="img.jpg" /> </div> <div class="img-wrap"> < ...

Ways to extract JSON data from multiple JSON arrays

Within the snippet below, I am attempting to extract the value of women. Right now, I can successfully retrieve 1. Personal care appliances and 2. Jewelry. However, if I try to check any checkbox after that, I encounter an error stating "Uncaught TypeError ...

Strategies for Addressing the OWASP Top 10 Web Application Security Risks in AngularJS

Currently, I am using HDIV to enhance the security of JSF and Spring MVC applications by addressing OWASP top 10 security risks. Now, I am faced with the challenge of implementing the same level of security in AngularJS. Are there any libraries out there ...

Maintain user input within the table following a page refresh

I have been working on developing a table that allows users to edit it. I successfully created a script that adds comments to the table, but unfortunately, these comments disappear when the page is refreshed. I understand that I may need some additional to ...

``A recently added pathway in the Yeoman generator now leads users directly back to the

Currently, I am utilizing the yeoman generator known as generator-angular-fullstack from https://github.com/angular-fullstack/generator-angular-fullstack To kickstart my project, I used the following command: yo angular-fullstack Later on, I wanted to i ...