Using ng-repeat to pass a parameter into a function triggered by ng-click

Check out the code snippet provided:

<div>
  <div class="list-group">
    <a class="list-group-item" ng-click="c.selectItem(note.sys_id)" 
       ng-repeat="note in data.notes">
      <h4 class="list-group-item-heading">
        {{note.title}}
      </h4>
      <p class="list-group-item-text">
        {{note.sys_id}}
      </p>
    </a>
  </div>
</div>

In the rendered output, note.sys_id is successfully displayed. However, I am trying to pass this value to the ng-click function above. I have attempted the following code modifications without success:

 ng-click="c.selectItem(note.sys_id)"
 ng-click="c.selectItem({{note.sys_id}})" 

Answer №1

https://jsfiddle.net/1q8mdb3z/

ng-click="c.selectItem(note.sys_id)"

It is recommended to ensure that your function is correctly implemented for the desired outcome. It is assumed that your scope should resemble something like:

$scope.c = {
    selectItem = function(id) {
      // do something with id
    }
}

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

Ways to switch out the background image using jQuery

I am currently using jQuery to dynamically change the background image of a web page. Right now, I have implemented two separate buttons that toggle between Image A and Image B. By default, Image A is displayed on the page. My goal is to enhance this func ...

Tips for sending data through AJAX before the browser is about to close

My issue is with a javascript function that I've called on the html unload event. It seems to be working fine in Google Chrome, but for some reason it's not functioning properly in Firefox and IE. <script> function fun() { ...

Encountering difficulties in setting up an Angular 5 project with angular-cli

Despite multiple re-installations, I am unable to use angular-cli 1.6 with ng. sudo npm install -g @angular/cli --unsafe-perm /usr/bin/ng -> /usr/lib/node_modules/@angular/cli/bin/ng npm WARN @schematics/<a href="/cdn-cgi/l/email-protection" class= ...

What is the limitation of including a string constant with "</script>" inside a <script> block?

I am genuinely curious about this: I thought that the following code would be valid within an HTML document: <script> var test = "<script>why? </script>"; </script> However, it turns out that this leads to an "unterminated str ...

retrieve data from the API response using a node request

I initiated an API request using the request method. Everything seems to be functioning properly, but I am encountering difficulty extracting the results from the response. The snippet of my code in question is as follows: app.get('/events/:query&a ...

Struggling to delete an item from an Array within Mongoose

Having trouble removing an element from an array model in mongoose by its _id. It's strange because the same method is working fine in other parts of my code, but not here. I've spent hours trying to debug it, but maybe my tiredness is affecting ...

Using JavaScript promises to handle connection pooling and query execution

I am contemplating whether this approach is on the right track or if it requires further adjustments. Should I consider promisifying my custom MySQL getConnection method as well? request: function(queryRequest) { return new Promise(function(re ...

Express API developed with the use of Node.js

In the process of creating a weather application API using Express in Node.js, I have decided not to utilize a database since no data needs to be saved. The application enables users to input a city name, and the weather information is fetched directly fro ...

Tips for managing Ajax JSON response in a PhoneGap application

Although there are a few posts on this topic, I am struggling to piece together the necessary components to make it work. I am in the process of converting a web application into an app using phonegap and I am attempting to create a search form that retri ...

Exploring the Realm of Angular Controllers and Services: Embracing Triumphs and

Currently in the process of creating a service layer for an existing web app using Angular. I am transitioning $http requests and data manipulation to custom Angular services. While I have a good understanding of Dependency Injection in services, I am enco ...

Why isn't the function call working within a directive?

I've implemented Angular Object Table (https://github.com/ekokotov/object-table) to display some basic data from my web api service and it's working well. For a few of the entries, I added a Delete button to allow users to remove them. I have a ...

Performing synchronous POST requests to manipulate data in a SQL database using AJAX

My goal is to send synchronous calls to a page that will handle the SQL insertion of words I am posting. However, due to the large number of chunks and the synchronous nature of SQL, I want each AJAX call to be processed one after another. for (chunk = 1; ...

I possess a pair of arrays, and I aim to transfer certain elements from Array1 to Array2 while maintaining their references

Looking to implement two JavaScript arrays using AngularJS. My goal is to transfer elements from Ar1 to Ar2, and then have any changes made to the values in Ar2 automatically update the values in Ar1 as well. ...

Is there a way to remove elements from a canvas using jquery?

I implemented a jquery code snippet from this source to add a falling confetti effect on my webpage. You can view the demo page by clicking here. The code works smoothly, and I noticed that I can use the start and stop functions to control the updates. Ho ...

Instructions on uploading a PDF file from a Wordpress page and ensuring the file is stored in the wp-content upload directory folder

What is the process for uploading a PDF file on a WordPress page? <form action="" method="POST"> <input type="file" name="file-upload" id="file-upload" /> <?php $attachment_id = media_handle_upload('file-upload', $post->I ...

Utilizing Google APIs to split a route among multiple locations

I am facing a scenario where A laundry company operates from one shop location. The laundry company has 3 trucks available (n trucks). The laundry company needs to deliver washed clothes to multiple locations (n locations). https://i.sstatic.net/ULup8.pn ...

Bypass the Array.reduce method in JavaScript

I'm currently working on finding an elegant solution to a toy example pattern. The goal is to stop the reduce algorithm immediately and return 0 when an element with a value of 0 is encountered, without processing the rest of the elements. let factor ...

Circular graphs displaying percentages at their center, illustrating the distribution of checked checkboxes across various categories

Looking for a JavaScript script that displays results in the form of circles with percentage values at their centers, based on the number of checkboxes checked in different categories. The circle radius should be determined by the percentage values - for e ...

Bird's-eye view captured by a high-angle camera

As I rotate a sphere around the z-axis, I'm looking for a way to prevent the camera from causing motion sickness by creating a stable elevated view of the sphere. How can I achieve this without the camera's movements being so jarring? If you&apo ...

Initiate the setInterval function upon clicking the button

Is there a way to successfully start setInterval when the user presses a button with ID #begin? I have attempted various methods, but they all seem to prevent setInterval from working at all. Any suggestions on how to make this work correctly? Thank you! ...