techniques for utilizing dynamic variables with the limitTo filter in AngularJS

<div class="container">
    <div class="row" ng-repeat="cmts in courCmt.argument"
        ng-init="getUserInfo(cmts)">

        <div class="col-sm-1 col-xs-2">
            <div class="thumbnail">
                <img class="img-responsive user-image"
                    ng-src="{{cmts.imagePath || 'defaultimage.png'}} ">
            </div>
            
        </div>
        

        <div class="col-sm-11 col-xs-10" style="padding-left: 10px">
            <div>
                <div>
                    <strong>{{cmts.username}}</strong>
                </div>
                <div>{{cmts.commentText}}</div>

                <small><a style="color: #0088cc" >Like</a>&nbsp&nbsp&nbsp&nbsp<a
                    class="reply-btn" style="color: #0088cc;"    ng-click="replyComment(cmts.cId,cmts)" >Reply</a>&nbsp&nbsp&nbsp&nbsp<span
                    class="text-muted"> {{cmts.createDate | date:'MMM d, y h:mm:ss a '}}</span></small><br>
                <strong><a id="quantity{{cmts.cId}}" style="color: #0088cc" ng-click="showAllReplies(cmts.cId)" ng-if ="cmts.replies.length>1"><span class="glyphicon glyphicon-menu-down"></span>See all {{cmts.replies.length}} replies </a></strong>
            </div>
            

            <div class="row"  ng-repeat="rep in cmts.replies | orderBy : '-createDate' | limitTo:quantity{{cmts.cId}}"
                ng-init="getUserReplyInfo(rep)" style="padding-left: 40px">
                <div class="col-sm-1 col-xs-2">
                    <div class="thumbnail" style="max-width: 70%; max-height: 70%">
                        <img class="img-responsive user-photo"
                            ng-src="{{rep.imagePath || 'defaultimage.png'}}">
                    </div>
                    
                </div>


                <div class="col-sm-11 col-xs-10" style="padding-left: 0px">
                    <div>
                        <div>
                            <strong>{{rep.username}}</strong>
                        </div>
                        <div>{{rep.replyText}}</div>
                        
                        <small> <a style="color: #0088cc">Like</a>&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp
                            <span class="text-muted">{{rep.createDate | date:'MMM d,y h:mm:ss a'}}</span></small>
                    </div>

                    
                </div>

            </div>
            <strong><a ng-hide="toggleValue{{cmts.cId}}" id="quantity1{{cmts.cId}}" style="color: #0088cc" ng-click="hideMoreReplies(cmts)">Show Less</a></strong>
            <div id="addReply{{cmts.cId}}" style="display:none">


                <div class="col-sm-1 col-xs-2" >
                    <img
                        ng-src="{{profileImagePath || 'defaultimage.png'}} " style="max-width: 60%; max-height: 60%">
                </div>
                <div class="col-sm-11 col-xs-10">
                    <textarea ng-model="replyCommentText" class="form-control" rows="1"
                         style=" width: 95%" ng-enter="saveReply(replyCommentText,cmts.cId,cmts.courseArgumentId,cmts.userId,user.id)"></textarea>
                </div>

            </div>
        </div>

        
    </div>


    
</div>
<script>

        $scope.showAllReplies = function(cmts){
            $("#quantity"+cmts.cId).hide();
            $("#quantity1"+cmts.cId).show();
            $scope["toggleValue"+cmts.cId] = false;
            $scope["quantity"+cmts.cId] ='';
        }

        $scope.hideMoreReplies = function(cmts){
            $("#quantity1"+cmts.cId).hide();
            $("#quantity"+cmts.cId).show();
            $scope["toggleValue"+cmts.cId] = true;
            $scope["quantity"+cmts.cId] = 1;
        }
</script>

Answer №1

To easily get rid of the mustaches, follow these steps

   ng-repeat="replyComment in courseComments.replies |orderBy : '-commentDate' | limitTo:courseComment.cId"

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

Using dynamic, deferred loading of scripts in JavaScript

Is it necessary to create a reference for a dynamic, lazy import that is used multiple times in a script? For example, if there are 2 event handlers importing different functions from the same module: /* index.js */ window.addEventListener("click", (e) =&g ...

Combining AngularJS with Servlets: A Seamless Integration

I am attempting to retrieve a JSON object from a servlet by calling a function through a link in my HTML code. Below is the HTML link that calls the fTest function: <td><a href="" ng-controller="minaplantaCtrl" ng-click="fTest(x.id_camion_descar ...

Is there a way to trigger $q notify without initiating a $digest cycle?

Within my application, the $digest cycle typically takes around 5ms to complete. I heavily utilize $q.defer with deferred.notify throughout my codebase, but I've encountered an issue. Each time deferred.notify is triggered, it schedules a new digest c ...

Unable to retrieve JSON element using Fetch

I'm attempting to retrieve a JSON file and exhibit its components within a div. Here is the JSON data I have: [ { "0":{ "host_id":"129230780", "host_names":"STK Homes", ...

Step-by-step guide on populating input fields with JSON data for each row

As a beginner in Programming, I have been searching for an answer to the following problem on this site for days but haven't been able to figure it out yet. To explain briefly, there will be an input form where the user can define the number of rows ...

Incorporating a switch button for toggling functionality in a Rails application

I attempted to convert a select tag into a JavaScript toggle on/off switch within my Rails application. After some searching, I came across a straightforward solution on the W3Schools website. http://www.w3schools.com/jquerymobile/tryit.asp?filename=tryj ...

How to retrieve the content/value from a textfield and checkbox using HTML

I'm encountering an issue with my HTML code where I am unable to extract data from the HTML file to TS. My goal is to store all the information and send it to my database. Here is a snippet of the HTML: <h3>Part 1 : General Information</h3 ...

How can one utilize electron's webContents.print() method to print an HTML or text file?

Electron Version : 2.0.7 Operating System : Ubuntu 16.04 Node Version : 8.11.1 electron.js let win = new BrowserWindow({width: 302, height: 793,show:false}); win.once('ready-to-show', () => win.hide()); fs.writeFile(path.join(__dirname ...

Unable to showcase array JSON values on HTML using ng-model

Utilizing ngTagInput for autocomplete textbox and successfully receiving suggestions. To display the values of data-ng-model (named "list") I am using: {{list}} and it is showing correctly. However, when selecting "list1", the display appears as: [{"lis ...

Unable to precisely reach the very bottom of the scrollbar

When trying to move to the bottom of the scrollbar, I seem to reach a bit higher than the actual bottom. https://i.stack.imgur.com/Vt83t.png Here is my code: ws.onmessage = function (event) { var log = document.getElementById('log') ...

Angular is unable to eliminate the focus outline from a custom checkbox created with Boostrap

Have you noticed that Angular doesn't blur out the clicked element for some strange reason? Well, I came up with a little 'fix' for it: *:focus { outline: none !important; } It's not a perfect solution because ideally every element sh ...

How to implement the ECharts animated bar chart in Angular version 16?

The animated bar chart in ECharts functions perfectly on Stackblitz. You can check it out here in the Stackblitz Angular 16 demo. However, attempting to run the same demo in a local Angular 16 project led to the following errors. Error: src/app/animated- ...

Navigate to the grandchild state with a specific parameter using ui-router's sref in the

Is there a way to create a sref that will navigate me to a grandchild state while also having a URL parameter for the child state? Check out this pseudo code example: .state( 'foo', {url:'/', template:'<div ui-view></div ...

Creating a draggable element in JavaScript using React

I've been attempting to create a draggable div element, but I'm encountering some perplexing behavior. The code I'm using is directly from w3schools and it functions correctly for them, however, in my implementation, the div always shifts to ...

Creating numerous duplicates of a highly nested immutable Object can be done by using a combination of spread operators

I am currently working on retrieving data from firebase/firestore using Javascript. I have created a function where I retrieve my products collection and pass this data to the React state.products by utilizing the setState() method. My objective is to tra ...

I am encountering an issue where req.body is returning as undefined

After creating a controller with the code below: app.post('/users', (req, res) => { console.log(req.body); const user = new User({ name: req.body.name, email: req.body.email }); user.sa ...

Sharing data between view and controller in Laravel: a guide

Currently, I am developing a product cart feature that includes subtotal and grand total values displayed within <span> tags. My goal is to pass the grand total value to the controller for further processing. However, I encountered an issue where the ...

Tips for updating a JSON object value in Node.js

Storing a JSON object in a JSON file is important for passing data during an API call. To update the object, replace "it-goes-here" with the following {} block. Newly updated data: { "parenturl":"xxx.com", "user ...

trouble encountered while sending data to php using ajax and json

Despite trying multiple solutions, my script is still not working properly. It functions without the $_POST value and without JSON, but when both are included, it fails to work. The error message displayed by the function is as follows: <b>Notice< ...

Retrieving the checkbox's status from the database

I have implemented a basic checkbox that updates its state in the database when clicked or unclicked. Is there a way to retain this state and have it displayed as checked if the page is refreshed? Essentially, I want the checkbox to remember its last state ...