javascript - Using a watch inside a link is causing an infinite digest cycle. -


I'm trying to write a command that adds a digit with one color.

I've already made an attempt, and Plunker's instructions are here:

 . Directive ('scorebox', function () {function link ($ $ radius, $ elem, $ attr) {var one = 1; $ scope. $ Watch (Pctscore & lt; = 0.4) {rating = 'less';} And if (pctScore & lt; = 0.6) ('[score, ptsPossible]', function (new value) {pctScore = newValue [0] / new value [1] {Rating = 'med';} and if (pctScore & Lt; = 0.8) {rating = 'high';} and if (pctScore == 1) {rating = 'perfect';} $ elem.removeClass (); $ elem $. Elem.addClass (rating); $ elem Return (restricted: 'e', ​​scope: {Score: "=", ptsPossible: "="}, link: link (newname [0] + "/" + newname [1]);});}; return }}   

Let me know some problems Are here First of all, it is very clear to me that I not inside a link function inside $ watch Want to do I am making an intense digestive cycle, and it is not good. I'm still not sure why, though.

  • I am not connecting DOM correctly even though I am calling $ elem.removeClass () , it is not working - the element is any class Keeps it first.

    What is the right way to do this?

    1. As @mikid said, there is no need to look at both Score and PTP potential, since you only want to make a change in the score (at least in this situation you are presenting) to react.

    2. Here's the problem, do you include the removeClass function instead of jqLite jQuery if jQuery is included in the code before the angular If not done, angular instead will use jqLite functions, which is like a small, very simple version of jQuery. This is also slightly different. Jquery's removeClass () will remove all classes, no passes will be passed. JqLite will not do this, it will remove those classes that you pass in the form of parameters.

      You have never included jQuery, so it is happening what is happening. You can see that jQuery is now included in the top, and everything works as expected and also $ Watch is very simple.

  • Comments

    Popular posts from this blog

    Verilog Error: output or inout port "Q" must be connected to a structural net expression -

    jasper reports - How to center align barcode using jasperreports and barcode4j -

    c# - ASP.NET MVC - Attaching an entity of type 'MODELNAME' failed because another entity of the same type already has the same primary key value -