单击“角度”中的“编辑”按钮时,数据未形成表格

时间:2018-11-12 08:41:56

标签: javascript angular angular6

单击Edit按钮时传递给AssignmentAudit.component.ts的数据是:

onEdit(nas:any){
 console.log(nas);

 this.assignmentAudit.auditorGroupNo=nas.assignmentAudit[0].auditorGroup.groupDesc;
 this.assignmentAudit.assignmentDate=nas.assignmentAudit[0].auditorGroup.assignmentDate;
 this.assignmentAudit.id=nas.assignmentAudit[0].id;
 this.assignmentAudit.selectionNo=nas.selectionId;
 this.assignmentAudit.magNo=0;

}

console.log(nas);数据是: enter image description here

我的表格有两个输入字段:

<form name="form" #f="ngForm" (ngSubmit)="f.form.valid &&  onSubmit()" novalidate class="">
<div class="form-group row">
   <div class="col-md-6">
      <label for="auditorGroup">Auditor Group</label>
      <select class="form-control" id="auditorGroup" required [(ngModel)]="assignmentAudit.auditorGroupNo" name="auditorGroup"
      #auditorGroup="ngModel"
      [ngClass]="{ 'is-invalid': f.submitted && auditorGroup.invalid }"
      required
      >
      <option *ngFor="let title of auditorgroups" [value]="title.auditorGroupId">{{title.groupDesc}}</option>
      </select>
      <div *ngIf="f.submitted && auditorGroup.invalid" class="invalid-input">
         <div *ngIf="auditorGroup.errors?.required">Auditor Group is required</div>
      </div>
   </div>
   <div class="col-md-6">
      <div class="form-group">
         <label for="assignmentDate">Assignment Date</label>
         <input type="date" id="assignmentDate"  class="form-control" name="assignmentDate" placeholder="Please enter the Assignment Date" [(ngModel)]="assignmentAudit.assignmentDate" #assignmentDate="ngModel"
         [ngClass]="{ 'is-invalid': f.submitted && assignmentDate.invalid }"
         required />
         <div *ngIf="f.submitted && assignmentDate.invalid" class="invalid-input">
            <div *ngIf="assignmentDate.errors?.required">Assignment Date is required</div>
         </div>
      </div>
   </div>
</div>
<button type="submit" style="margin-bottom: 50px;" class="btn btn-success pull-right">Submit</button>
</form>

表单看起来很简单:

enter image description here

我需要采取的行动是: enter image description here

我已经在表单中使用 [(ngModel)] =“ assignmentAudit.assignmentDate” 绑定了数据,当我在按钮上单击onEdit()操作后将值放在 this.assignmentAudit上时.assignmentDate = nas.assignmentAudit [0] .auditorGroup.assignmentDate; ,因为应该双向绑定,所以数据不会自动以形式显示。有什么问题吗?

0 个答案:

没有答案