我正在将角材料2和角6一起用于数据源,并且工作正常。但是我想在单击链接(编辑)后从行列表中选择一个特定项目。
当我单击编辑链接时,我希望表单被预先填写和预选。我知道选择是在后台进行的,因为如果我提交按钮,则可以看到数据。但是我可以看到物品;如您所见,将显示加号取消按钮:
my_activities: MatTableDataSource<intfMyActivities>;
this.rForm = this.formBuilder.group({
'activityid':[null,[Validators.required]],
'edu':[null,[Validators.required,validYesNo]],
'exp':[null,[Validators.required,validYesNo]]
});
editActivity(event,row_id) {
/*
Edit the given activity. put the data to the form
*/
event.preventDefault();
this.editing_row=row_id;
this.rForm.controls['activityid'].setValue(this.my_activities.data[row_id].activity_id);
this.rForm.controls['edu'].setValue(this.my_activities.data[row_id].has_education);
this.rForm.controls['exp'].setValue(this.my_activities.data[row_id].has_experience);
}
在html中:
<a href="#" (click)="editActivity($event,row_index)"><mat-icon>edit</mat-icon></a>
<mat-card-content>
<mat-form-field class="w-100">
<mat-select class="w-100" placeholder="{{'Activities.haveEducation' | translate}}" formControlName="edu">
<mat-option value="1">{{'Shared.yes' | translate}}</mat-option>
<mat-option value="0">{{'Shared.no' | translate}}</mat-option>
</mat-select>
</mat-form-field>
</mat-card-content>