I have the following (simplified) example where I can not find why my function is called too often, NG-Dual render material (I can explain this by code, shows a better topic than this).
(I had read about the NG-repeat-start / ng-repeating end but I do not know how it helps me.)
Any helpful input Thanks in advance for!
& lt; Table & gt; & Lt; TR & gt; & Lt; Th & gt; & Lt; Strong> Date & lt; / Strong> & Lt; / Th & gt; & Lt; Td ng-repeat = "day in day" & gt; & Lt ;! - Where is an array array of 6 days - & gt; {{Day | Date: 'EEE D'}} & lt; / Td> & Lt; / TR & gt; & Lt; TR & gt; & Lt; Th & gt; & Lt; Strong> Participants & lt; / Strong> & Lt; / Th & gt; & Lt; Td ng-repeat = "day in day" & gt; & Lt; Span ng-if = "! User user (1)" & gt; & Lt; A href = "" & gt; User does not participate & lt; / Span & gt; & Lt ;! - It provides 6 times, but the user performs the process () is called 36 times (6 * 6?) - why is it? - & gt; & Lt; / TD & gt; & Lt; / TR & gt;
Update
Thank you for your reply, Woot4Moo! I'm sorry, I'm still confused:
You say that my code makes it:
& lt; Span ng-if = "! UserParticipates (1)" & gt; & Lt; A href = "" & gt; User does not participate & lt; / Span & gt; & Lt; Span ng-if = "! User user (1)" & gt; & Lt; A href = "" & gt; User does not participate & lt; / Span & gt; & Lt; Span ng-if = "! User user (1)" & gt; & Lt; A href = "" & gt; User does not participate & lt; / Span & gt; & Lt; Span ng-if = "! User user (1)" & gt; & Lt; A href = "" & gt; User does not participate & lt; / Span & gt; & Lt; Span ng-if = "! User user (1)" & gt; & Lt; A href = "" & gt; User does not participate & lt; / Span & gt; & Lt; Span ng-if = "! User user (1)" & gt; & Lt; A href = "" & gt; User does not participate & lt; / Span & gt;
But this is not really what I see. I have only one line once in every row (6 times), 'user does not take part', this is the function within ng, which is called 36 times. Why do not I know, because my ng-repetition does not seem nested in each other ...? Since ng-if condition $ watch begins, you do not know how often it will be called,
But you can be assured that he will be asked a lot, and every method will be called many times. Any time someone who dials a digest cycle page, a Digest cycle is started to dial the page or essentially someone on the page Even event (complete AJAX, button click etc.) Digest cycle time to confirm once and no other changes for each clock at least run twice (early shift). Registering the watch causes an extra call in itself.
This is not temporarily for evaluating 100 or 1000 times during the application for such expressions.
If your function does anything other than checking a normal condition like a == b
then you should calculate the result and caching it. For example, in your controller, you can watch $ USD on user id, when user_id changes, you set the currentUserParticipating = userParticipates (userId)
and then you use the current user , Participate in your NG-if.
Comments
Post a Comment