Adjust the range directly in ng-repeat from the directive

I am working with HTML code that looks like this:

<div dir-paginate="x in comments | itemsPerPage: commentsPerPage">
HERE IS DIRECTIVE FROM BLEOW
</div>

My goal is to update the commentsPerPage scope within the directive...

Below is a directive that is nested inside an ng-repeat loop:

angular.module('commentsApp')
        .directive("addreply", addreply);



//ADD REPLY FUNCTION
function addreply(createCommentFactory)
{
    //CREATING BUTTON FOR REPLY AND CALL LINK FUNCTION
    var addReplys = {
        link: link,
        restrict: "EA",
        transclude: true
    };

    return addReplys;

    function link(scope, element, attrs)
    {
        scope.form = {
            reply: ""
        };



        //CALL FACTORY TO ADD NEW REPLAY ON CLICK
        element.bind('click', function () {
            scope.addReply = function (el) {
                createCommentFactory.saveComment(scope.form.reply[el.id], scope.project_id, el.id, el.level + 1)
                        .success(function (data) {
                            scope.commentsPerPage = scope.comments.length;
                        })
                        .error(function (data) {
                            console.log(data);
                        });
                // RESET REPLY TEXT AREA
                scope.form.reply = "";
            };

        });
    }
}

I have attempted to update

scope.commentsPerPage = scope.comments.length;
, but it is not working as expected. Can anyone provide a solution for this?

Answer №1

The scope of your directive is inherited prototypically from its parent. This means that scope.commentsPerPage actually shadows the parent's scope.commentsPerPage.

To quickly resolve this issue, you can use $parent.commentsPerPage. For a more sustainable solution, consider restructuring your code to utilize controller.property instead of scope.property.

For a comprehensive explanation, refer to this informative article.

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

Executing external Javascript within an HTML document

Just diving into this realm, so please have patience with me. I've got an external js file linked in my HTML. The JS code is solid and functions properly in Fiddle - https://jsfiddle.net/0hu4fs4y/ <script src="js/noti.js"></script> <sc ...

Encountered a JSON error while implementing in an ASP project

Currently, I am working with JavaScript and C# in aspnet. My goal is to pass 3 values from the Asp Page to the code behind, using the Json method. Below is how I achieve this: //initialize x, y and nome var requestParameter = { 'xx': x, 'yy ...

Error: AJAX response shows as NaN, indicating that the requested resource was not found

Attempting to create a search engine using AJAX. When typing in the search box, nothing happens. After inspecting the element and opening the console, an error message is displayed: script.js:19 GET http://localhost/var/www/html/pendaftaran-siswa/NaN 404 ( ...

Vue/Vuex - using async dispatch for AJAX requests in multiple components

I am working with vuex and using a store module to load user lists in my app through ajax. After the list is loaded, it doesn't fetch again if it's already present in the vuex store. I have implemented this logic in the main application layout as ...

Automatically retrieve the generated PDF file upon completion (Node.js and Express)

I've been utilizing the node module html-pdf to seamlessly convert my HTML into PDF format. The conversion process goes smoothly, but I'm encountering difficulties when it comes to downloading the file once it's been generated. Below is the ...

The functionality of a basic each/while loop in jQuery using CoffeeScript is not producing the desired results

I've been experimenting with different methods to tackle this issue. Essentially, I need to update the content of multiple dropdowns in the same way. I wanted to use an each or a while loop to keep the code DRY, but my experience in coffeeScript is li ...

Error: The property 'ss' cannot be accessed because it is undefined

Our main source page will be index.html, while Employees.html is where our results end up. An error occurred: TypeError - Cannot read property 'ss' of undefined Error in the code: let rating = req.body.ss; Seeking assistance please >< C ...

Develop a JavaScript function to declare variables

I am currently attempting to develop a small memory game where the time is multiplied by the number of moves made by the player. Upon completion of all pairs, a JavaScript function is executed: function finish() { stopCount(); var cnt1 = $("#cou ...

Having issues with utilizing $fetchState in Nuxt 2.12

Recently, I've been exploring the new functionality outlined in the documentation. However, I'm encountering an error that states : Property or method "$fetchState" is not defined on the instance but referenced during render. Despite clearly ...

Combining arrays using value comparison in Google Analytics and MongoDB

Help me out, Stack! This job is driving me crazy. Here's what I'm working on: Using the Google Analytics NodeJS SDK, I'm retrieving data about the most visited pages of my website. By leveraging Google's user-friendly URLs (slugs), I se ...

Only output to the console if the data returned from an AJAX request has been

Here is a script that I created: <script type="text/javascript> $('.storage').html(""); setInterval(function(){ $.get('./playcommand.php', function(data) { if($('.storage').html() !== data){ ...

end the node.js automated testing process

I'm currently using Jasmine and Zombie JS to create automated tests. I have integrated Drone.io for Continuous Integration, and the tests are executing successfully. However, there seems to be an issue where after passing the tests, the process does n ...

Creating an Array module in Node JS

Adding a prototype to the Array class can be done in native javascript with the following code: var myArray = Array; myArray.prototype.myMethod = function(){} var testArray = new myArray(); testArray.contains(); Now I need to achieve this using a nod ...

jQuery plugin for manipulating and adding days to dates

Within my Ruby on Rails application, there is a specific field where users can input a date. The current format for this date value is as follows: $('#search_form_handover_date').val() #returns "15-07-2014 09:00" I am looking to modify this dat ...

Using Protractor loggingPrefs, learn how to initiate and cease recording performance logs at specific points during testing, and stop the process once it is completed

When conducting my test, I utilize loggingPrefs to record all network calls and HTTP requests. I am interested in exploring the possibility of implementing a way to log performance logs after a specific test step has been executed and then stopping it once ...

Error: Uncaught object in AngularJS ngRoute

I keep encountering an uncaught object error in my browser console while trying to load my AngularJS application. I am unsure if this issue is related to ng-route.js or if it's something else, as the error message only says 'uncaught object' ...

Guide on storing images in a designated folder using CodeIgniter

My code is located in view/admin_view2.php <?php echo form_open_multipart('home_admin/createBerita'); ?> <div class="form-group" > <label class="control-label">upload foto</label> <inpu ...

What is the best way to direct users to an input field within a dynatree title?

I am currently utilizing Dynatree to display a tree view, and my goal is to focus on an input field within the dynatree title element. However, I am encountering an issue where the focus is being lost. My code attempts to address this problem but unfortun ...

The issue with viewing next/image properly only occurs on desktops using a responsive layout. I would like for the image

<Image src={APIImagePath} alt={t("common:tokens")} layout="fill" className={styles.img} /> Showing on a desktop screen: https://i.stack.imgur.com/gT2ZF.png Viewing on a tablet: https://i.stack.imgur.com/yeABR.png ...

Incorporating a new text tag

Is there a way to add a text label for every circle that can be rotated and have its color changed? I'm looking for a solution that doesn't involve JSON data, but instead retrieves the necessary information from somewhere else. var w = 3 ...