javascript - (Why) does having a directive that "calls itself" in a finite ng-repeat lead to a stack overflow from infinite recursion? -


edit: see this plunker simplified version of problem (an sscce).


the following code seems cause infinite recursion problem:

statement.directive.html

<textarea></textarea><br /> <button ng-click='statement.newstatement()'>new statement</button> <button ng-click='statement.newsubstatement()'>new substatement</button> <hr /> <statement   ng-repeat='statement in statement.curr.sections'   curr='statement'   parent='statement.curr'> </statement> 

i don't know why though. statement.curr.sections 0 (when tested it). wouldn't directive not "instantiated/implemented"?


<p ng-repeat='statement.curr.sections'>x</p> 

doesn't cause problems.

wrapping in ng-if doesn't fix problem.

<div ng-if='statement.curr.sections > 0'>   <statement     ng-repeat='statement in statement.curr.sections'     curr='statement'     parent='statement.curr'>   </statement> </div> 

edit: doesn't work either (but realize chose bad variable names).

<textarea></textarea><br /> <hr /> <statement   ng-repeat='item in statementctrl.curr.sections'> </statement> 

code on github.

i took @ github code it's confusing. naming throwing brain in circles, start clarifying that.

for directive, should use prefix it's clear you're referencing directive: ie. mystatements, elstatement, whatever.

for service , controller, use suffix: statementservice, statementcontroller.

what don't understand:

<button ng-click='statement.newstatement()'>new statement</button> 

what statement. referring here? when become initialized/binded view? edit: nevermind see that's controller.

ok, you've got template directive, referencing directive itself...

hmm, not sure if directive can have child directive itself. seems quite infinite loop when template trying render. because if next layer/directive doesn't have data, still needs bootstrap directive , template, leads load next directive... , never finishes.

seems anti-pattern. use case? trying draw fractal? lol

in terms of fractals, need pass limit (ie. when fractal becomes small can't see it, there's no longer point draw it). imposing limit, can stop infinitely trying draw.

tl;dr: if data empty, child directive still being initialized/rendered.


Comments

Popular posts from this blog

python - TypeError: start must be a integer -

c# - DevExpress RepositoryItemComboBox BackColor property ignored -

django - Creating multiple model instances in DRF3 -