2017-06-05 101 views
0
我在運行 ng build --prod有以下錯誤

當這是編譯工作,爲ng buildng server角度構建失敗創建生產版本

錯誤在NG:{PATH} /儀表/促銷/加推廣/促銷 - form.component.html(33,13):屬性'controls'在類型'AbstractControl'上不存在。

ERROR in ng:{path}/dashboard/promotions/add-promotion/promotion-form.component.html (33,13): Property 'controls' does not exist on type 'AbstractControl'. 

ERROR in ng:{path}/dashboard/promotions/add-promotion/promotion-form.component.html (45,13): Property 'controls' does not exist on type 'AbstractControl'. 

ERROR in ng://{path}/dashboard/promotions/add-promotion/promotion-form.component.html (45,13): Property 'controls' does not exist on type 'AbstractControl'. 

下面是我的組件表單生成器和HTML

this.promotionForm = this.fb.group({ 
     'id':[null], 
     'title': [null, Validators.compose([Validators.required, Validators.maxLength(50), 
     Validators.pattern('[a-zA-Z ]*'), Validators.required,Validators.minLength(1)])], 
     'description': [null, Validators.compose([Validators.required])], 
     'imageSrc': [null, [Validators.required]], 
     'contactPerson' : this.fb.group({ 
          'name': [null, [Validators.required]], 
          'email': [null, [Validators.required,Validators.pattern(/^\w+([\.-]?\w+)*@\w+([\.-]?\w+)*(\.\w{2,3})+$/)]], 
          'phone': [null, [Validators.required, 
          Validators.pattern(/^[0-9]{10}$/)]] 
         }), 
    }); 

的HTML組件

<form [formGroup] ="promotionForm" (submit)="submit(promotionForm.value)"> 
    <--Top Form fields--> 
    <table class="full-width" cellspacing="0"> 
    <tr > 
     <div formGroupName="contactPerson"> 
     <td > 
      <md-input-container class="full-width"> 
      <input mdInput 
        formControlName="name" 
        placeholder="Sales Person" [ngModel]="promoData?.contactPerson.name" 
        [formControl]="promotionForm.controls['name']"> 
      <div *ngIf="!promotionForm.controls.contactPerson.controls.name.valid 
          && (promotionForm.controls.contactPerson.controls.name.dirty)"> 
       <span class="primary">Please enter a valid name.</span> 
      </div> 
      </md-input-container> 
     </td> 
     <td> 
      <md-input-container class="full-width"> 
      <input mdInput formControlName="phone" 
        placeholder="Mobile Number" [ngModel]="promoData?.contactPerson.phone" 
      [formControl]="promotionForm.controls['phone']"> 
      <div *ngIf="!promotionForm.controls.contactPerson.controls.phone.valid 
          && (promotionForm.controls.contactPerson.controls.phone.dirty)"> 
       <span class="primary">Please enter a valid phone number.</span> 
      </div> 
      </md-input-container> 
     </td> 
     <td> 
      <md-input-container class="full-width"> 
      <input mdInput formControlName="email" 
        placeholder="Email Address" [ngModel]="promoData?.contactPerson.email"> 

      <div *ngIf="!promotionForm.controls.contactPerson.controls.email.valid 
          && (promotionForm.controls.contactPerson.controls.email.dirty)"> 
       <span class="primary">Please enter a valid email.</span> 
      </div> 
      </md-input-container> 
     </td> 
     </div> 
    </tr> 
    </table> 
....</form> 
+0

這可能會有所幫助https://github.com/angular/angular-cli/issues/6099 –

+0

謝謝你的回覆,我檢查了這個鏈接,但是他們沒有解釋這個答案,我有點困惑與它 – 123Ex

回答

2

一般情況下,你不應該訪問這樣的控制,這是你應該什麼做:

change

promotionForm.controls['name'] 

promotionForm.get('name') 

,改變

promotionForm.controls.contactPerson.controls.phone 

promotionForm.get('contactPerson.phone') 

發現別人並修復它們。

+0

謝謝你的迴應,編譯問題固定與此,但驗證郵件不顯示 – 123Ex

+0

這將是另一個問題,我的朋友。 – Milad

+0

一切在開發模式下正常工作,當我切換到prod提到的問題來了,現在導致另一個,你知道如何解決? – 123Ex