0

I'm dynamically loading templates which is working fine. Now my concern is I need to add a JavaScript logic to template

I need to use something like this in my template.

{{ var entries = 0; }}
{{ for(var r = 0; r < d; r++) }}

Suppose my template returns this HTML

<div ng-repeat="x in names" ><span>{{x.name}}</span>{{some logic here which is plain js. var a=[] if(a=b){}}}</div>

My question is how to achieve this.

4
  • so what is the problem. Commented Dec 22, 2016 at 10:21
  • i need too add this code in my json. i know ng-reapeat will repeat all the data in it Commented Dec 22, 2016 at 10:26
  • 1
    What do you mean "need to add this code in JSON". Commented Dec 22, 2016 at 10:30
  • @Ved my bad i have edited my question Commented Dec 22, 2016 at 10:43

3 Answers 3

2
<div ng-repeat="entry in entries track by $index">
    {{entry}},{{$index}}
  </div>
Sign up to request clarification or add additional context in comments.

Comments

1

Use ng-repeat.

  <div ng-repeat="entry in entries">
    {{entry}}
  </div>

If you need the index:

  <div ng-repeat="entry in entries">
    {{entry}},{{$index}}
  </div>

Docs: https://docs.angularjs.org/api/ng/directive/ngRepeat

Comments

1
<div ng-init="entries[0,1,2,3,4]">//Use ng-int to initialize data

<div ng-repeat="data in entries">// use ng-repeat to loop over
    {{data}}
  </div>

</div>

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.