angularjs $window.onclick performs better than ng-click2019 Community Moderator ElectionHow do I detect a click outside an element?Trigger a button click with JavaScript on the Enter key in a text boxImprove INSERT-per-second performance of SQLite?Why are elementwise additions much faster in separate loops than in a combined loop?How does data binding work in AngularJS?Why is it faster to process a sorted array than an unsorted array?Is < faster than <=?“Thinking in AngularJS” if I have a jQuery background?AngularJS: Service vs provider vs factoryWhy is printing “B” dramatically slower than printing “#”?

Should QA ask requirements to developers?

Can someone explain what is being said here in color publishing in the American Mathematical Monthly?

How much stiffer are 23c tires over 28c?

Good allowance savings plan?

Why doesn't this Google Translate ad use the word "Translation" instead of "Translate"?

Look through the portal of every day

My story is written in English, but is set in my home country. What language should I use for the dialogue?

Do f-stop and exposure time perfectly cancel?

Replacing Windows 7 security updates with anti-virus?

Do items de-spawn in Diablo?

Unreachable code, but reachable with exception

Best approach to update all entries in a list that is paginated?

Is there any way to damage Intellect Devourer(s) when already within a creature's skull?

Grey hair or white hair

How do I express some one as a black person?

Should I take out a loan for a friend to invest on my behalf?

Single word request: Harming the benefactor

Does "variables should live in the smallest scope as possible" include the case "variables should not exist if possible"?

Aliens englobed the Solar System: will we notice?

Why is Beresheet doing a only a one-way trip?

Force user to remove USB token

PTIJ: Why can't I eat anything?

MTG: Can I kill an opponent in response to lethal activated abilities, and not take the damage?

What does a stand alone "T" index value do?



angularjs $window.onclick performs better than ng-click



2019 Community Moderator ElectionHow do I detect a click outside an element?Trigger a button click with JavaScript on the Enter key in a text boxImprove INSERT-per-second performance of SQLite?Why are elementwise additions much faster in separate loops than in a combined loop?How does data binding work in AngularJS?Why is it faster to process a sorted array than an unsorted array?Is < faster than <=?“Thinking in AngularJS” if I have a jQuery background?AngularJS: Service vs provider vs factoryWhy is printing “B” dramatically slower than printing “#”?










0















I had a scenario where I have to make some alterations in localstorage as well as in some other data of the controller, this logic was supposed to be done on click of anywhere in whole page. This code was supposed to close all colorpickers if click was done anywhere on the body but not on the colorpicker button, but if clicked on colorpicker button then close all others colorpickers and open only the respective one. First I tried using ng-click which was working okay but the pace of closing all colorpickers and opening of respective one was very slow.



Note that I tried using $scope.$apply(); but that didn't work but instead it started giving me error that angularjs digestion is already in progress. Then I used $window.onclick which worked perfectly and the pace of colorpickers closing and opening was also very fine. I am wondering why $window.onclick worked better than ng-click. That function is as follows



$window.onclick = function (e) ;









share|improve this question




























    0















    I had a scenario where I have to make some alterations in localstorage as well as in some other data of the controller, this logic was supposed to be done on click of anywhere in whole page. This code was supposed to close all colorpickers if click was done anywhere on the body but not on the colorpicker button, but if clicked on colorpicker button then close all others colorpickers and open only the respective one. First I tried using ng-click which was working okay but the pace of closing all colorpickers and opening of respective one was very slow.



    Note that I tried using $scope.$apply(); but that didn't work but instead it started giving me error that angularjs digestion is already in progress. Then I used $window.onclick which worked perfectly and the pace of colorpickers closing and opening was also very fine. I am wondering why $window.onclick worked better than ng-click. That function is as follows



    $window.onclick = function (e) ;









    share|improve this question


























      0












      0








      0








      I had a scenario where I have to make some alterations in localstorage as well as in some other data of the controller, this logic was supposed to be done on click of anywhere in whole page. This code was supposed to close all colorpickers if click was done anywhere on the body but not on the colorpicker button, but if clicked on colorpicker button then close all others colorpickers and open only the respective one. First I tried using ng-click which was working okay but the pace of closing all colorpickers and opening of respective one was very slow.



      Note that I tried using $scope.$apply(); but that didn't work but instead it started giving me error that angularjs digestion is already in progress. Then I used $window.onclick which worked perfectly and the pace of colorpickers closing and opening was also very fine. I am wondering why $window.onclick worked better than ng-click. That function is as follows



      $window.onclick = function (e) ;









      share|improve this question
















      I had a scenario where I have to make some alterations in localstorage as well as in some other data of the controller, this logic was supposed to be done on click of anywhere in whole page. This code was supposed to close all colorpickers if click was done anywhere on the body but not on the colorpicker button, but if clicked on colorpicker button then close all others colorpickers and open only the respective one. First I tried using ng-click which was working okay but the pace of closing all colorpickers and opening of respective one was very slow.



      Note that I tried using $scope.$apply(); but that didn't work but instead it started giving me error that angularjs digestion is already in progress. Then I used $window.onclick which worked perfectly and the pace of colorpickers closing and opening was also very fine. I am wondering why $window.onclick worked better than ng-click. That function is as follows



      $window.onclick = function (e) ;






      javascript angularjs performance onclick angularjs-ng-click






      share|improve this question















      share|improve this question













      share|improve this question




      share|improve this question








      edited Mar 7 at 7:41









      Deblaton Jean-Philippe

      8,29323758




      8,29323758










      asked Mar 7 at 7:39









      Awais NasirAwais Nasir

      357




      357






















          1 Answer
          1






          active

          oldest

          votes


















          1














          $window is a reference to the browser's window object. (See here for details: https://docs.angularjs.org/api/ng/service/$window)



          ng-click causes a digest cycle through $scope.$apply. (Details here: https://docs.angularjs.org/guide/scope)



          Relevant part:




          Listener directives, such as ng-click, register a listener with the
          DOM. When the DOM listener fires, the directive executes the
          associated expression and updates the view using the $apply() method.




          Therefore, $window.onclick executes faster, because it doesn't cause a digest cycle.






          share|improve this answer






















            Your Answer






            StackExchange.ifUsing("editor", function ()
            StackExchange.using("externalEditor", function ()
            StackExchange.using("snippets", function ()
            StackExchange.snippets.init();
            );
            );
            , "code-snippets");

            StackExchange.ready(function()
            var channelOptions =
            tags: "".split(" "),
            id: "1"
            ;
            initTagRenderer("".split(" "), "".split(" "), channelOptions);

            StackExchange.using("externalEditor", function()
            // Have to fire editor after snippets, if snippets enabled
            if (StackExchange.settings.snippets.snippetsEnabled)
            StackExchange.using("snippets", function()
            createEditor();
            );

            else
            createEditor();

            );

            function createEditor()
            StackExchange.prepareEditor(
            heartbeatType: 'answer',
            autoActivateHeartbeat: false,
            convertImagesToLinks: true,
            noModals: true,
            showLowRepImageUploadWarning: true,
            reputationToPostImages: 10,
            bindNavPrevention: true,
            postfix: "",
            imageUploader:
            brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
            contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
            allowUrls: true
            ,
            onDemand: true,
            discardSelector: ".discard-answer"
            ,immediatelyShowMarkdownHelp:true
            );



            );













            draft saved

            draft discarded


















            StackExchange.ready(
            function ()
            StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f55038435%2fangularjs-window-onclick-performs-better-than-ng-click%23new-answer', 'question_page');

            );

            Post as a guest















            Required, but never shown

























            1 Answer
            1






            active

            oldest

            votes








            1 Answer
            1






            active

            oldest

            votes









            active

            oldest

            votes






            active

            oldest

            votes









            1














            $window is a reference to the browser's window object. (See here for details: https://docs.angularjs.org/api/ng/service/$window)



            ng-click causes a digest cycle through $scope.$apply. (Details here: https://docs.angularjs.org/guide/scope)



            Relevant part:




            Listener directives, such as ng-click, register a listener with the
            DOM. When the DOM listener fires, the directive executes the
            associated expression and updates the view using the $apply() method.




            Therefore, $window.onclick executes faster, because it doesn't cause a digest cycle.






            share|improve this answer



























              1














              $window is a reference to the browser's window object. (See here for details: https://docs.angularjs.org/api/ng/service/$window)



              ng-click causes a digest cycle through $scope.$apply. (Details here: https://docs.angularjs.org/guide/scope)



              Relevant part:




              Listener directives, such as ng-click, register a listener with the
              DOM. When the DOM listener fires, the directive executes the
              associated expression and updates the view using the $apply() method.




              Therefore, $window.onclick executes faster, because it doesn't cause a digest cycle.






              share|improve this answer

























                1












                1








                1







                $window is a reference to the browser's window object. (See here for details: https://docs.angularjs.org/api/ng/service/$window)



                ng-click causes a digest cycle through $scope.$apply. (Details here: https://docs.angularjs.org/guide/scope)



                Relevant part:




                Listener directives, such as ng-click, register a listener with the
                DOM. When the DOM listener fires, the directive executes the
                associated expression and updates the view using the $apply() method.




                Therefore, $window.onclick executes faster, because it doesn't cause a digest cycle.






                share|improve this answer













                $window is a reference to the browser's window object. (See here for details: https://docs.angularjs.org/api/ng/service/$window)



                ng-click causes a digest cycle through $scope.$apply. (Details here: https://docs.angularjs.org/guide/scope)



                Relevant part:




                Listener directives, such as ng-click, register a listener with the
                DOM. When the DOM listener fires, the directive executes the
                associated expression and updates the view using the $apply() method.




                Therefore, $window.onclick executes faster, because it doesn't cause a digest cycle.







                share|improve this answer












                share|improve this answer



                share|improve this answer










                answered Mar 7 at 23:50









                Florian LimFlorian Lim

                5,02722226




                5,02722226





























                    draft saved

                    draft discarded
















































                    Thanks for contributing an answer to Stack Overflow!


                    • Please be sure to answer the question. Provide details and share your research!

                    But avoid


                    • Asking for help, clarification, or responding to other answers.

                    • Making statements based on opinion; back them up with references or personal experience.

                    To learn more, see our tips on writing great answers.




                    draft saved


                    draft discarded














                    StackExchange.ready(
                    function ()
                    StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f55038435%2fangularjs-window-onclick-performs-better-than-ng-click%23new-answer', 'question_page');

                    );

                    Post as a guest















                    Required, but never shown





















































                    Required, but never shown














                    Required, but never shown












                    Required, but never shown







                    Required, but never shown

































                    Required, but never shown














                    Required, but never shown












                    Required, but never shown







                    Required, but never shown







                    Popular posts from this blog

                    How to get text form Clipboard with JavaScript in Firefox 56?How to validate an email address in JavaScript?How do JavaScript closures work?How do I remove a property from a JavaScript object?How do you get a timestamp in JavaScript?How do I copy to the clipboard in JavaScript?How do I include a JavaScript file in another JavaScript file?Get the current URL with JavaScript?How to replace all occurrences of a string in JavaScriptHow to check whether a string contains a substring in JavaScript?How do I remove a particular element from an array in JavaScript?

                    Can't initialize raids on a new ASUS Prime B360M-A motherboard2019 Community Moderator ElectionSimilar to RAID config yet more like mirroring solution?Can't get motherboard serial numberWhy does the BIOS entry point start with a WBINVD instruction?UEFI performance Asus Maximus V Extreme

                    List of MPs elected to the English parliament in 1640 (April) Contents List of constituencies and members See also Notes References Navigation menueNational Archives – The Glynde Place ArchivesCobbett's Parliamentary history of England, from the Norman Conquest in 1066 to the year 1803'Aldermen in Parliament', The Aldermen of the City of London: Temp. Henry III – 1912onepage&q&f&#61, false 229