What is the reason behind having 3 watchers for 1 binding in AngularJS?

Take a moment to view the screenshot provided below

https://i.sstatic.net/qLcem.png

In the screenshot, it is evident that there are #3 watchers for a single binding.

Would someone care to explain the reason behind this?

P.S: I am utilizing AngularJS Batarang to assess performance.

var app = angular.module('app', []);

app.controller('appCtrl', function ($scope, $timeout) {
    $scope.name = 'vikas bansal';
})
<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8>
    <title>Document</title>
    <script src="http://ajax.googleapis.com/ajax/libs/angularjs/1.5.5/angular.min.js"></script>
    <script src="app.js"></script>
</head>

<body>
    <div ng-app="app" ng-controller="appCtrl">
        {{name}}
    </div>
</body>

</html>

Answer №1

It seems that Angular Batarang is reporting an incorrect number of watchers. After cross-checking with multiple sources, it appears that every tool except AngularJS Batarang indicates just one watcher in your code. For further details, you can refer to this question along with the following function:

(function () { 
    var root = angular.element(document.getElementsByTagName('body'));

    var watchers = [];

    var f = function (element) {
        angular.forEach(['$scope', '$isolateScope'], function (scopeProperty) { 
            if (element.data() && element.data().hasOwnProperty(scopeProperty)) {
                angular.forEach(element.data()[scopeProperty].$$watchers, function (watcher) {
                    watchers.push(watcher);
                });
            }
        });

        angular.forEach(element.children(), function (childElement) {
            f(angular.element(childElement));
        });
    };

    f(root);

    // Remove duplicate watchers
    var watchersWithoutDuplicates = [];
    angular.forEach(watchers, function(item) {
        if(watchersWithoutDuplicates.indexOf(item) < 0) {
             watchersWithoutDuplicates.push(item);
        }
    });

    console.log(watchersWithoutDuplicates.length);
})();

You may also want to consider using the Watchers extension for Chrome, which also confirms the presence of just one watcher.

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

Angular ng-repeat not recognizing nested ng-if conditions

Hey there, I'm trying to make sure that only the option corresponding to the code used by the client to log in is displayed. The HTML should show the option that matches the client's login code. View: <div class=""> <select id="custo ...

Tips for expanding the content of a blogger page to fill the entire frame of the page

Check out this page: . Currently, the video on the page does not fill up the entire screen. Any suggestions for a solution? ...

Preserving the "height" declaration in jQuery post-Ajax request (adjusting height after dropdown selection loads product information, resetting heights of other page elements)

Looking for a way to set a height on product descriptions using jQuery? Check out the solution below: https://www.example.com/product-example Here is the code snippet that can help you achieve this feature: $(document).ready(function() { var $dscr = $ ...

"Beginner's guide to utilizing JQuery and AJAX with PHP

I am struggling to grasp the concept of using AJAX and jQuery to post data without reloading the page. Specifically, I am facing issues with the form reloading the page and not updating variables. Here is the code I have been working on: Initially, I was ...

using node.js to extract a cookie from a 302 redirect

Need help simulating a login using node.js. The request is a post method and returns a 302 status code. However, when trying to simulate the request in node, I encounter the following error: Error handling unrejected promise: StatusCodeError: 302 Upon i ...

Utilizing winston to generate multiple log files with set maximum sizes and daily rotation

Currently, I am utilizing winston for logging with a maximum size and daily rotation. I am interested in having this functionality with one file per API endpoint to define multiple log files. Is there a way to achieve this? Displayed below is my winston ...

How to retrieve a form submission from Jquery HandsonTable in PHP using $_POST

Recently, I've started diving into the world of javascript/jquery/ajax. My current project involves fetching data from a jQuery handsonTable () and integrating it with my PHP code. The process includes generating a table from a MySQL database, utili ...

All menus effortlessly sliding out simultaneously

I'm having an issue with my navigation bar. I want each link to slide its corresponding DIV up or down when clicked. However, all the DIVs are sliding and when clicking on the same link everything slides up. How can I fix this problem? This is my HT ...

What is the best way to achieve a consistent style for two tables?

I would like to achieve uniform styling for each row. The first row, which contains 'het regent vandaag', has the following CSS rule: .attachments-table td { margin: 0 5px; padding: 10px 8px; line-height: 1.4; white-space: pre-wr ...

JavaScript Class Emit Signal for establishing a sequence of interconnected events

My Vue project includes a JavaScript class specifically for mobile devices. I'm looking to have this class emit a signal once the property 'hasEnded' is set to True for my object. How can I achieve this and chain together other events based ...

Having an issue with Local Storage returning undefined

I've been working on a form to input values and show the data on a different page after submission. Below is my form: <meta name="viewport" content="width=device-width, initial-scale=1"> <link rel="stylesheet" hr ...

Utilizing JSON File as an Array in a Node.JS Environment

I'm struggling with converting a .json file into an array object using NodeJS, Here's the JSON content: { "cat": { "nani": "meow" }, "dog": { "nani": "woof" } } index.js: const array = require('../../data/use ...

I would prefer not to add another database table just to differentiate between team members and friends. Can you provide assistance with this?

Instead of creating another table named friends in Strapi and linking it to Visual Studio Code, I have opted to use a Characters table for both team members and friends. This way, I can input new data only at Characters and filter it to differentiate betwe ...

Tips on refreshing a div using jQuery while maintaining the functionality of addEventListener

Hi, I am facing an issue with updating the "div" element. The refresh works fine, but after refreshing when I try to click on the updated "div", the addEventListener in my JavaScript code does not seem to work anymore. Can someone please explain why this i ...

What is the best way to encapsulate a function that uses `this.item.findElement()` from Selenium in a separate file?

I'm currently working on setting up a Selenium Webdriver and Cucumber.js test environment using Node.js. In the homePageSteps.js file, I have a check to verify if a banner exists on a page: Then('there should be a banner', async function() ...

Populate your HTML with JSON data

I need some guidance on how to achieve a specific task. I have a PHP file that retrieves data from a MySQL database and returns it in JSON format. Now, I want to display this data in HTML with "data_from_json" replaced by "18.5". Any assistance would be gr ...

Using AngularJS to bind a dictionary to an ng-repeat function

Hello everyone! I have a dictionary with keys and lists of objects returned from my controller. I want to bind this data to a table or another element using the ng-repeat directive. This is how the data looks when returned from the controller: https://i.s ...

What is the best way to choose a tag from an app within components or views?

In my main component file, I added a color picker input in the navigation section to change the background color of the application. This works fine as the body tag can be accessed easily within the DOM. Furthermore, I store the selected color in local st ...

Leveraging the power of AngularJS within an ASP.NET MVC architecture, bypassing

Looking to incorporate AngularJS with ASP.NET MVC for my website, while utilizing Active Directory for authentication. ASP.NET MVC seems like the best choice for routing and handling authentication/authorization. My plan is to create a _Layout.cshtml page ...

The difference between using an event listener directly in HTML vs. using the add

Looking to customize the behavior of an HTML element using event listeners? There are two ways to accomplish this: <form class="my-form"> <input type="submit"/> </form> <script> document.querySelectorAll(&quo ...