2016-04-07 21 views
1

bir dizin istediğiniz istediğim yazma:ekrana test iç içe ng-tekrarı

metin metin

sorum gerçek

sorum gerçek

metin metin

benim ques'im Gerçek siyon

sorum gerçek

sorum gerçek

metin metin

sorum gerçek

sorum gerçek

. 1 2 1 2 3 1 2

Ben $ ebeveyn ile sınamak

$ index + 1: 1 1 2 2 2 3 3

ama istediğim

<span ng-repeat="step in steps"> 
    <b>{{step.statement}}</b><br> 
    <span ng-repeat="question in step.questions"> 
     <b>{{??????}}</b> {{question.question}} {{question.response}}<br> 
    </span> 
</span> 

Ben $ indeksi + 1 ile sınamak 1 2 3 4 5 6 7 ...

cevap

2

Önceki döngülerin length kodunu ileriye taşıyabilir ve bir sonraki $index numarasına ekleyebilirsiniz. Şunun gibi:

<div ng-init="lastLength=[]"> 
     <span ng-repeat="step in steps" ng-init="lastLength[$index]=step.questions.length"> 
      <b>{{step.statement}}</b><br> 
      <span ng-repeat="question in step.questions" style="padding-left:50px;"> 
       <b>{{lastLength[$parent.$index-1]+$index+1}}</b> {{question.question}} {{question.response}}<br> 
      </span> 
     </span> 
</div> 

Çalışma Örneği:

var app = angular.module('xApp', []).controller('xCtrl', function($scope) { 
 
    $scope.steps = [{ 
 
    statement: 'St 1', 
 
    questions: [{ 
 
     question: 'q 1', 
 
     response: 'rs 1' 
 
    }, { 
 
     question: 'q 2', 
 
     response: 'rs 2' 
 
    }] 
 
    }, { 
 
    statement: 'St 2', 
 
    questions: [{ 
 
     question: 'q 4', 
 
     response: 'rs 4' 
 
    }, { 
 
     question: 'q 5', 
 
     response: 'rs 5' 
 
    }, { 
 
     question: 'q 6', 
 
     response: 'rs 6' 
 
    }] 
 
    }] 
 
})
<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.2.23/angular.min.js"></script> 
 
<div ng-app="xApp" ng-controller="xCtrl" ng-init="lastLength=[]"> 
 
    <span ng-repeat="step in steps" ng-init="lastLength[$index]=step.questions.length"> 
 
     <b>{{step.statement}}</b><br> 
 
     <span ng-repeat="question in step.questions" style="padding-left:50px;"> 
 
      <b>{{lastLength[$parent.$index-1]+$index+1}}</b> {{question.question}} {{question.response}}<br> 
 
     </span> 
 
    </span> 
 
</div>