1

In my AngularJS app, I created a recursive template.

For illustration, it works something like this:

<div ng-repeat="item in stuff">
     <div ng-include="'myTemplate.html'" onload="item = item"></div>
</div>


<script type="text/ng-template" id="myTemplate.html">
         <h1> {{levelsDeep | "root"}} </h1>
         <h2> {{item.content}} </h2>
         <div ng-include="'myTemplate.html'" onload="item in item.innerItem; levelsDeep = levelsDeep+'->'"></div>
</script>

In this recursive template, I want the top level line to read "root" and the inner levels to read '->->->' etc, depending on how deeply nested they are.

Is there a filter to check if levelsDeep has not yet been defined (like in the first step) and then print "root" if this is so?

1
  • can you try creating a plunker? Commented Nov 12, 2014 at 17:48

1 Answer 1

3

You can use the javascript OR (||) operator

{{levelsDeep||"root"}}

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.