What is parentValueWatch in AngularJS?

I use batarang to determine the source of some performance issues. One of the biggest culprits was my own code, but this parent thing ValueWatch now heads the diagrams, and I have no idea where it is or what launches it. My brains are lying on the floor from so much googling ... does anyone know?

(AngularJS v1.2.24)

enter image description here

+5
source share
1 answer

ParentValueWatch is when a directive checks in its parent area the visibility of a change in some values ​​and, therefore, must be changed itself.

Consider a simple directive

 { restrict:"AE", scope:{ foo:'=' } } 

Now let's say in the parent scope, foo is an object.

 $parent.$scope.foo = { bar:"zim" } 

Each cycle of $digest , for the child $ region, it is necessary to check the value of the parent region foo and each of its properties.

If foo was really a big and deeply nested object, it would take a lot of time, so it takes so long.

Inside HTML, it might look like this:

 <div parent-directive> <div foo-directive foo=bar></div></div> 

One quick task is to β€œdry” the values ​​using ng-init.

 <div parent-directive> <div foo-directive ng-init='zug={bar:$parent.foo.bar}' foo=zug></div></div> 

Now the value tied to the new object. You lose easy binding, but gain performance.

It is always a compromise.

+5
source

Source: https://habr.com/ru/post/1213173/


All Articles