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

Activate modifications in a distinct column?

I've been exploring a solution to achieve a similar functionality where clicking or hovering on headings in a column brings up corresponding text in another column. My idea is to use list items with a carousel for this purpose, but I'm facing so ...

Can someone assist me in understanding the proper syntax for the Node.js function that inserts a document into Watson's Discovery service from the watson-developer-cloud library?

I'm attempting to upload JSON documents into a Discovery collection using the Node.js watson-developer-cloud JDK. Here is the relevant code snippet: const DiscoveryV1 = require('watson-developer-cloud/discovery/v1'); const discovery = new D ...

Tips for troubleshooting objects within an Angular template in an HTML file

When I'm creating a template, I embed some Angular code within my HTML elements: <button id="btnMainMenu" class="button button-icon fa fa-chevron-left header-icon" ng-if="(!CoursesVm.showcheckboxes || (CoursesVm.tabSelected == 'curren ...

What is the best way to implement collision detection using raycasting?

For my university project, I am looking to implement collision similar to what is shown in this example. However, I am facing an issue where collision is only working on the top of the object. I referred to this for guidance. My goal is to add collision to ...

Struggling with retrieving data from a file in Angular service while using node-webkit. Unable to make it functional

I've been struggling for a while and gone through numerous solutions, but I can't seem to figure out why this code isn't functioning: I have a requirement to pass data between controllers, so I created a service, right? (The data is coming ...

Comparing Two Items between Two Arrays

I have a scenario where I need to compare values in two arrays by running a condition. The data is pulled from a spreadsheet, and if the condition is met, I want to copy the respective data. For instance, I aim to compare two cells within a spreadsheet - ...

Tips for personalizing text and icon colors in the TableSortText element of Material-ui

My Goal: I aim to empower users with the ability to apply customized styles to my EnhancedTable component by utilizing a styles object containing properties like headCellColor, headCellBackgroundColor, bodyCellColor, bodyCellBackgroundColor, and more. The ...

Revamp the md-select Container

Hello there! I'm looking for a stylish way to revamp the design of the md-select Window. Specifically, I aim to customize the background and hover effects. Despite my attempts to modify the .md-select-menu-container in CSS, it proved unsuccessful. I ...

`Creating a new directive within angularJS`

Currently, my dynatree directive is functioning properly. I am wondering if there is a way to trigger a re-invocation of the directive from a controller in order to rebuild itself. The reason for this is that my data is stored in session storage and the ...

Transferring data from a form to a function in JavaScript

Hey there! I've been working on a form that sends a value to a new window, but for some reason, the value val2 is showing up as null in the new window instead of being passed. Here's my code: function sendValue(value) { ViewImg = window.ope ...

What causes the break in Bamboo tasks once Protractor finishes?

Following the completion of my Protractor task, I am observing a 2-minute delay in my bamboo build. Below are the log details: [12/8/2015 5:10 PM] Agnew, Tyler: build 08-Dec-2015 16:45:24 Finished in 62.66 seconds build 08-Dec-2015 16:45:24 [32 ...

Encountering problems with ajax technology

As a newcomer to Laravel and Ajax, I am facing an issue with displaying the state of the selected country in a dropdown list. Although the data is successfully fetched from Laravel and received through Ajax, I am struggling to dynamically add it to the H ...

"Exploring the world of JavaScript through the lens of time

This summer, I have the opportunity to assist a friend with some JavaScript challenges on his website. The main issue seems to revolve around technical difficulties with online form submissions. Unfortunately, there are instances where we struggle to verif ...

Alert: It is invalid for an <a> element to be nested inside another <a> element according to validateDOMNesting

I've been experimenting with using react-router in conjunction with reactstrap and create-react-app. While setting up the routing within my application, I encountered a need to utilize state for the reactstrap components. To achieve this, I converted ...

What causes the function to return null when using router.get('/:x',..), whereas router.get('/foo/:x',...) works perfectly fine?

After weeks of struggling to identify the root cause of my issue, I finally pinpointed it. Now, I'm curious to understand the reason behind this behavior. I constructed an api for my mongodb server following the techniques I learned in school, utiliz ...

The margins within the div of the new tab are not applying as expected

Greetings! Currently, I am in the process of generating a dynamic form within a new tab using JavaScript. For some reason, the margin effects on the div element are not being applied correctly. Despite my attempts to set the margins using both classes and ...

When implementing Firebase Cloud Messaging with React, the token generated by firebase.messaging().getToken() will vary with every refresh

I'm working on a React web app using Gatsby and I want to integrate push notifications through FCM. My firebase-messaging-sw.js service worker is set up, and I'm trying to retrieve a token using the following method in my app: messaging .req ...

Personalize the loading bar using JavaScript

Currently, I am utilizing a basic progress bar from Bootstrap. However, I have the desire to design a custom progress bar similar to this: Unfortunately, I am uncertain about how to create such a unique progress bar. Perhaps there is an existing JavaScri ...

Sending Angular base64 image data to the server

I am encountering an issue while attempting to upload a base64 image from Angular to ExpressJS. The image is being created using html2canvas to generate the base64 representation. When I try to upload the imageData in its current format, I receive an error ...

Is there a way to design a form that appears as though it's levitating above a div element?

I am new to web development and currently practicing by converting PSD designs into HTML pages. I am facing an issue where I need to create a form that appears to be floating on top of a div, with the form being taller than the div itself. Here is an illu ...