2017-09-16 69 views
3

我最近在Angular4活性形式開始反應形式陣列,我想創建下面的結構基礎上的表單陣列創建數組不同的驗證

"ContactPoints": 
[{"ContactPointID":33,"EntityID":9,"System":"phone","Value":"1234567890","Use":"work","Rank":1,"InUseStart":"2017-07-14T00:00:00","InUseEnd":"2017-10-22T00:00:00"}, 
{"ContactPointID":34,"EntityID":9,"System":"phone","Value":"1234567890","Use":"home","Rank":1,"InUseStart":"2017-07-14T00:00:00","InUseEnd":"2017-10-22T00:00:00"}, 
{"ContactPointID":35,"EntityID":9,"System":"fax","Value":"1234567890","Use":"work","Rank":1,"InUseStart":"2017-07-14T00:00:00","InUseEnd":"2017-10-22T00:00:00"}, 
{"ContactPointID":36,"EntityID":9,"System":"email","Value":"[email protected]","Use":"work","Rank":1,"InUseStart":"2017-07-21T00:00:00","InUseEnd":"2017-10-29T00:00:00"}, 
{"ContactPointID":37,"EntityID":9,"System":"email","Value":"[email protected]","Use":"home","Rank":1,"InUseStart":"2017-07-21T00:00:00","InUseEnd":"2017-10-29T00:00:00"}], 

下面是HTML語法,在這裏我需要得到相應的輸入在價值體系和使用價值將根據系統硬編碼值和驗證,在實現這一目標的任何建議將是非常有益的

<div class="col-md-4" formArrayName="ContactPoints"> 
       <div class="form-group form-group-default " formGroupName=0> 
        <label class="control-label">Main Number</label> 
        <input type="text" class="form-control" formControlName="Value"> 
       </div> 
      </div> 

<div class="col-md-4" formArrayName="ContactPoints"> 
        <div class="form-group form-group-default " formGroupName=1> 
         <label class="control-label">Main Number</label> 
         <input type="text" class="form-control" formControlName="Value"> 
        </div> 
       </div> 
+0

那麼您的驗證規則在哪裏? –

+0

@ AngularInDepth.com我想驗證也基於JSON的系統值來實現,假設如果「系統」:「電話」它應該觸發電話號碼驗證,我很困惑在哪裏把驗證規則放在上面的場景 –

+0

如何你聲明你的'FormGroup'實例嗎? – yurzui

回答