Once an ng-repeat is completed, I must extract and retrieve the 'id' of a specific element

Is it possible to retrieve the 'id' of the comment I'm replying to and save it for an Ajax call? I can easily access other data with ng-model, but using value="{{this.id}}" in a hidden input doesn't seem to work like in JQuery.

<script type="text/ng-template" id="comments-temp">
<div>
    <ul class="comments" ng-repeat="comment in ctrl.comments">
        <li>
            <div class="comment" id="{{comment.id}}">

                <div class="comment-author">
                    <a href="#" style="background-image: url('assets/img/tmp/agent-1.jpg');"></a>
                </div><!-- /.comment-author -->

                <div class="comment-content">
                    <div class="comment-meta">

                        <div class="comment-meta-author">
                            Posted by <a href="#">admin</a>
                        </div><!-- /.comment-meta-author -->

                        <div class="comment-meta-reply">
                            <a href="#" ng-click="showPanel = true">Reply</a>
                        </div>

                        <div class="comment-meta-date">
                            <i class="fa fa-calendar"></i><span>{{comment.dateAdded | date: 'medium'}}</span>
                        </div>
                    </div><!-- /.comment -->

                    <div class="comment-body">

                        <div class="comment-item" id="commentTitle">
                            <h6>{{comment.title}}</h6>
                        </div>
                     {{comment.body}}
                    </div><!-- /.comment-body -->
                </div><!-- /.comment-content -->
            </div><!-- /.comment -->

            <panel ng-show="showPanel">
                <div class="comment-create" ng-model="ctrl.reply">
                    <form method="post" action="?">

                        <div class="row">
                            <div class="col-sm-4">
                                <div class="form-group ">
                                    <label>Title</label>
                                    <input type="text" class="form-control" ng-model="ctrl.reply.title">
                                </div><!-- /.form-group -->
                            </div><!-- /.col-* -->

                            <div class="col-sm-4">
                                <div class="form-group hidden">
                                    <label>Title</label>
                                    <input type="text" class="form-control" ng-model="ctrl.reply.name">
                                </div><!-- /.form-group -->
                            </div><!-- /.col-* -->

                            <div class="col-sm-4">
                                <div class="form-group hidden">
                                    <label>ParentId</label>
                                    <input type="text" class="form-control" value="{{comment.id}}" ng-model="ctrl.reply.parentId">
                                </div><!-- /.form-group -->
                            </div><!-- /.col-* -->
                        </div><!-- /.row -->
                        <div class="form-group">
                            <label>Message</label>
                            <textarea class="form-control" rows="5" ng-model="ctrl.reply.body"></textarea>
                        </div><!-- /.form-group -->
                        <div class="form-group-btn">
                            <button type="button" ng-click="ctrl.replyComment(ctrl.reply); showPanel = false;" class="btn btn-primary pull-right">Post Reply</button>
                        </div><!-- /.form-group-btn -->
                    </form>
                </div>
            </panel>
            <div style="height:35px"></div>
        </li>
    </ul>
</div> <!--comment temp end-->

I hope this explanation makes sense. What I am trying to achieve is:

  <script>
function _replyComment(data){

                vm.commentData = data;
                vm.commentData.blogId = vm.blogId;
                vm.commentData.userId = page.currentUserId;
                vm.commentData.typeId = 1;
                vm.commentData.parentID = //??????? where I want the value the id of the comment I'm replying too 


                console.log(vm.commentData);
                comments.services.insert(data, _onSuccessComment, _onError);// my ajax is in a separate .js file.  it's not important for this demo
 }
  </script>

After this step, the challenge is nesting the replies in the DOM correctly. But that is a question for another day. This is where Jquery proves to be more convenient than angular.

Thank you!

Answer №1

holtc successfully resolved the issue at hand. My approach may seem circular, but I devised an additional click function that solely stored the comment's ID. Subsequently, I introduced a new controller variable and seamlessly integrated it into my _replyComment function.

   vm.getIdentifier = _getIdentifier;
            vm.identifierValue = null;

            function _getIdentifier(data){
                vm.identifierValue = data

                console.log(vm.identifierValue)

            }


            function _respondToComment(data){

                vm.commentData = data;
                vm.commentData.blogId = vm.blogId;
                vm.commentData.userId = page.currentUserId;
                vm.commentData.typeId = 1;
                vm.commentData.parentId = vm.identifierValue;
                console.log(vm.commentData);

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

Utilizing 'nestjs/jwt' for generating tokens with a unique secret tailored to each individual user

I'm currently in the process of generating a user token based on the user's secret during login. However, instead of utilizing a secret from the environment variables, my goal is to use a secret that is associated with a user object stored within ...

Uploading files with Laravel through Ajax

I am currently facing an issue while trying to upload files using Ajax and Laravel. Whenever I attempt to upload a file, it returns empty. The following is the method in Laravel: public function save_vehicles(Request $request){ $files=$request->fil ...

Having trouble with my Angular subscription - not behaving as I anticipated

I am facing an issue on my shop page where I have a FilterBarComponent as a child component. On initialization, I want it to emit all the categories so that all products are rendered by default. However, on my HomePageComponent, there is a button that allo ...

The Node.js application encounters a blank response when making a GET request to the API

As a newcomer to node.js, I'm attempting to describe the issue at hand as clearly as possible. If clarification is needed, please let me know. In my current node.js project, I am faced with a challenge where I need to take a code received from the re ...

Unlocking the power of RXJS by de-nesting subscriptions

Trying to resolve the nested subscription issue has become a time-consuming puzzle. I've experimented with mergeMap, flatMap, and switchMap without success. Unfortunately, the examples I've come across don't quite fit my needs, leaving me wi ...

Tips for Extracting Real-Time Ice Status Information from an ArcGIS Online Mapping Tool

My goal is to extract ice condition data from a municipal website that employs an ArcGIS Online map for visualization. I want to automate this process for my personal use. While I have experience scraping static sites with Cheerio and Axios, tackling a sit ...

Utilize array collections across various pages for increased efficiency

Currently, I am working with two pages - page1.php and page2.php. Each page has its own controller that handles specific functions. However, there are tabs within both pages that share the same functionality of obtaining a promise from a factory within the ...

JavaScript application throwing error: "require is not defined"

Currently, I am working on storing an array in a .json file using NodeJS. However, when trying to execute the code below, I encountered an error message saying require is not defined. Can someone provide some guidance on how to resolve this issue? let ans ...

Updating input value in React on change event

This is the code for my SearchForm.js, where the function handleKeywordsChange is responsible for managing changes in the input field for keywords. import React from 'react'; import ReactDOM from 'react-dom'; class SearchForm extends ...

Unable to retrieve basic profile data from LinkedIn Members using their email ID unless they are signed in

I am struggling to retrieve the basic profile details of Linkedin Members using their email ID. Despite my efforts, I haven't been able to find relevant information in the documentation. My attempt involved creating an app, initializing the JavaScrip ...

Transform the given text into components applicable to AngularJS

I have a dynamic dashboard with a JSON object that I populate with HTML elements in text format, like this: var items = [ {"id": "panel1", "description": "<div><a ui-sref='page1'>link a</a></div>"}, {"id": "panel2", "de ...

Vue project encountering issue with displayed image being bound

I am facing an issue with a component that is supposed to display an image: <template> <div> <img :src="image" /> </div> </template> <script> export default { name: 'MyComponent', ...

HTML5 canvas processing causing web worker to run out of memory

Within the Main thread: The source image array is obtained using the getImageData method. It is represented as a uint8ClampedArray to store the image data. Below is the code executed in a web worker: (This operation generates a high-resolution image, but ...

Preventing scrolling on a YouTube video embed

I have been working hard on developing my personal website. One issue I encountered is that when there is a YouTube video embedded in the site, it stops scrolling when I hover over it. I would like the main document to continue scrolling even if the mouse ...

Google Maps API now offers the ability to generate directions with up to 500 waypoints

I am facing a challenge with displaying a route on Google Maps using an array of 500 waypoints extracted from a GPS route. Google Maps is unable to create a direction or route with more than 23 waypoints, making it difficult to replicate the original GPS ...

Is it possible to refresh resources in Node.js without the need to restart the server?

Is there a middleware or library that allows access to files added after the server starts without requiring a restart? I currently use koa-static-folder, but it seems unable to handle this functionality. ...

The Ionic APK is failing to retrieve location data, however the system is displaying the location accurately

Why does my location not show up when running an Ionic apk file on a mobile device, even though the system shows the location? What could be causing this issue? Module.js file angular.module('ionic.example', ['ionic']) .co ...

Problem with Next.js router language settings

I have configured different locales for our application including uk and us. For the blog section, we can use either us/blog or just /blog for the uk locale. After switching to the us locale like this: (locale = "us") const updateRoute = (locale ...

Retrieve data from a different div, perform a subtraction operation, and dynamically update yet another div using jQuery

Looking to extract a specific div class value, subtract 500 from it, and display the result in another div. Unclear about the steps needed to show the subtraction outcome on the other div. Consider this scenario: <div class="main-value">6000</d ...

I am receiving a success message from webpack indicating that the compilation was successful, but I am encountering a blank page in the

My app.js looks like this: import Home from "./pages/home/Home"; import Login from "./pages/login/Login"; import Profile from "./pages/profile/Profile"; import Register from "./pages/register/Register"; import { Brow ...