2016-12-15 151 views
0

我正在慢慢推進到角度。在這一點上我有形式有幾個步驟,每個步驟由NG-形式,因爲每一步包含「繼續」按鈕,共同頭我有以下循環角度動態生成表單驗證

<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-包括和切片硬編碼,我想我的思念$範圍現在,爲NG-包括創建一個以及NG-重複,可能有人告訴我,我怎麼可以讓繼續按鈕取決於每個ng-form驗證結果? (我如何可以訪問最上面$範圍內的每個單獨的NG-形式的結果?)

回答

1

每個按鈕都可以訪問該表單的$錯誤,所以你可以有這樣的例子:

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

你也有NG - 形式被拼錯(NG-的),但我認爲這是一個僞影,你在粘貼/打字。

+0

不幸的是我沒有拼寫錯了,給出的例子能正常工作,如預期 – Raimonds

0

如果要禁用按鈕,如果的形式之一是無效的

我怎樣才能訪問每個單獨的ng表單導致最高的$範圍?

如果ng-repeat中的任何子表單無效,則可以用ng-form包裝ng-repeat並重復ng-form。

或者,如果你wan't阻止每個表單按鈕,然後

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