Dismiss
Announcing Stack Overflow Documentation

We started with Q&A. Technical documentation is next, and we need your help.

Whether you're a beginner or an experienced developer, you can contribute.

Sign up and start helping → Learn more about Documentation →

i want to iterate through array elements and print them one by one. currently i have this HTML code.

<div data-ng-repeat="i in range">
    <div ng-repeat="rhit in hits[i]">
      <p > {{ rhit }}</p>
     </div>
</div>

here

  • "range" is an array with values till 100([0,1,2,....,100])

  • "hits" is an array containing more than one element

if i try separately printing like this, it works

<p > {{ hit[0] }}</p>
<p > {{ hit[1] }}</p>
<p > {{ hit[2] }}</p>

i also tried this code but it doesn't print anything.

<div ng-repeat="rhit in hits">
     <p > {{ rhit }}</p>
</div>

this is my actual query result

"aggregations": { "by_id": { "doc_count_error_upper_bound": 0, "sum_other_doc_count": 0, "buckets": [ {

{"key":"60","doc_count":21,

"tops":{

"hits":{

"total":21,"max_score":2.2237754,

"hits":[{"_index":"automatch_testing","_type":"temp_135","_id":"AVU7i0nnXK6g_oqHu-az","_score":2.2237754,"_source":{"t_pacs_id":"34","t_id":"60","matching":"MO"}},

{"_index":"automatch_testing","_type":"temp_143","_id":"AVU7iOSeXK6g_oqHu-XY","_score":2.2237754,"_source":{"t_pacs_id":"30","t_id":"60","matching":"MO","t_match":"matched"}},

{"_index":"automatch_testing","_type":"temp_135","_id":"AVU7i0nlXK6g_oqHu-ay","_score":2.2237754,"_source":{"t_pacs_id":"28","t_id":"60","matching":"MO","UICriteria":"135","t_match":"matched"}}]}}}

here i want to print the field "t_pacs_id" of each document in hits...

is there any way the above code can be run?? please suggest.

many thanks.

here is the plunker

share|improve this question
    
can you please supply more information about your data than "•"hits" is an array containing more than one element"? right now, it's not clear if it is a typo between hit and hits or if it is a problem with your data layout. – Claies Jun 21 at 18:34

If you are interested to get the hits collection ith place then you could directly do hits[i] instead of having another ng-repeat

<div data-ng-repeat="i in range">
    <p> {{ hits[i] }}</p>
</div>
share|improve this answer
    
yeah i tried this too..still no output – Nihal Pratap Jun 21 at 18:36
    
Your update in question in big change in what you were asking before.. it would be great if you could provide us an plunkr/fiddle.. – Pankaj Parkar Jun 21 at 18:49
    
okay no problem – Nihal Pratap Jun 21 at 18:52

You say that separately printing something like this works:

<p > {{ hit[0] }}</p>

In that code, you are accessing an array named "hit", but in your code that does not work, you are using ng-repeat to iterate over an array named "hits". What do you get when you try:

<div ng-repeat="rhit in hit[i]">
share|improve this answer
    
i tried but no output. – Nihal Pratap Jun 21 at 18:34
    
What is the output of: <p > {{ hit[0] }}</p> ? (And can you verify that the value of hit[0] is an array?) – Dan Jun 21 at 18:36

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.