2016-12-15 4 views
0

각도가 천천히 진행됩니다. 이 시점에서 나는 각 단계를 포함하고 있기 때문에 버튼 및 일반 헤더 나는 그래서 그런 식으로 내가 같은 반복하고 있지 않다 루프를각도 동적 생성 양식 유효성 검사

<section ng-from="form12.{{step.id}}" ng-repeat="step in steps" id="{{step.id}}" ng-class="{active: currentSection == $index}"> 
     <h1 class="header">{{$index + 1}}. {{step.title}}</h1> 
     <div class="content"> 
      <ng-include src="step.template"></ng-include> 
     </div> 

     <!--and button code--> 
     <div class="content-body" ng-show="currentSection == $index"> 
      <button ng-show="$index != 0" class="btn prev" ng-click="prevSection()">Previous</button> 

      <button class="btn next" ng-click="nextSection()" ng-disabled="step{{$index+1}}.$invalid">{{isLastStep($index)}}</button> 
      <div style="clear: both;"> </div> 
     </div> 
    </section> 

을 다음있다 "계속", 각 단계는 NG-형태로 구성되어, 여러 단계로 양식을 가지고 버튼은 각 ng-form에 대한 코드입니다.

ng-include를 사용하기 전에 섹션을 하드 코딩 했으므로 이제 ng-include가 ng-repeat를 생성하므로 $ scope가 누락되었다고 가정합니다. 어떻게 작성해야합니까? 각각의 ng-form 검증 결과에 따라 계속 버튼을 사용할 수 있습니까? (어떻게 내가 맨 위의 $ 범위에서 각 NG 형태의 결과를 액세스 할 수 있습니까?)

답변

1

각 버튼은 그 형태의 $ 오류에 액세스 할 수 있습니다, 당신은 예를 들어이있을 수 있도록 :

<button class="btn next" ng-click="nextSection()" ng-disabled="form12.{{step.id}}.$invalid"> 

또한 NG가를 나는 당신이/입력 붙여에서 그 유물이었다 생각하지만, 티아, 잘못 (NG-)에서 철자.

+0

불행하게도 내가 철자 않았다 그것을 잘못, 주어진 예는 잘 작동 – Raimonds

0

당신이 양식 중 하나가

무효 인 경우 버튼을 비활성화하려면 어떻게 할 수 각 개별 양식에 액세스하십시오. 최상위 $ 범위가됩니까?

ng-repeat 형식으로 줄 바꿈 할 수 있으며 ng-repeat의 하위 형식이 유효하지 않은 경우 상위 ng 형식이 유효하지 않습니다.

또는 양식에 따라 버튼을 차단하는 wan't 경우 예상대로 다음

<button class="btn next" ng-click="nextSection()" ng-disabled="form12.{{step.id}}.$invalid">{{isLastStep($index)}}</button> 
관련 문제