2016-04-30 40 views
0

這裏我想創建一個頁面編號,每增加一次ng-repeat增量,但我得到的是第二個ng-repeat索引始終爲零,但使用索引首先ng-repeat通過$ parent很好地工作。$ index這怎麼解決? 這裏是代碼示例:

<div ng-repeat="chapter in plan.chapters" class="export-page" > 
         <div ng-repeat="section in chapter.sections track by section.id" class="export-page" ng-init="sectionindex = $index"> 

          <div class="header"> 
           <br> 
           <h2 class="headerTitle"> 
           <b>{{$root.selectedCompany.name + ' | ' + chapter.subject}}</b> 
           </h2> 
          </div> 

          <div class="content"> 
           <h1><b>{{chapter.subject}}</b></h1> 
           <h2 class="chapter" >{{section.subject}}</h2> 

           <br> 

           <p ng-if="section.content_type === 'text'"> 
           <div ng-bind-html="section.content.text"></div> 
           </p> 

           <p ng-if="section.content_type === 'table'"> 
           <numeric-table model="section.content" 
               disable-editing="true" 
               hide-input-controls="true"> 
           </numeric-table> 
           </p> 

           <p ng-if="section.content_type === 'aggregated-table'"> 
           <aggregated-table model="section.selectedTables"> 
           </aggregated-table> 
           </p> 

           <p ng-if="section.content_type === 'text-table'"> 
           <free-text-table model="section.content" 
               disable-editing="true" 
               hide-input-controls="true"> 
           </free-text-table> 
           </p> 

           <p ng-if="section.content_type === 'chart'"> 
           <multi-chart model="section.content" 
              tables="section.selectedTables" 
           > 
           </numeric-table> 
           </p> 
          </div> 
          <div class="footer col-xs-12"> 
           <div class="txt col-xs-11">copyright [email protected] {{$root.selectedCompany.name}}</div> 
           <div class="pp col-xs-1 ">Page{{sectionindex}} </div> 
          </div> 
         </div> 
        </div> 
+0

如何是代碼大塊有關的問題嗎?它沒有ng-repeat,也沒有$ index。澄清你的問題,發佈相關的代碼,精確解釋它產生的輸出,以及你想要的輸出。 –

+0

抱歉,複製粘貼問題 – mohamed

回答

0
<div ng-repeat="(index1 ,chapter) in plan.chapters" class="export-page" > 
    <div ng-repeat="(index2,section) in chapter.sections track by section.id" class="export-page" ng-init="sectionindex = $index"> 
     Outer Repeat Index{{index1}} 
     Inner Repeat Index{{index2}} 
    </div> 
</div>