初始化的时候创建表单
ngOnInit() {
this.retrieve();
this.createForm();
}
// 创建表单
createForm() {
this.form = this.formBuilder.group({
funcAllID: new FormControl(),
});
}
通过触发进行keys更新,此处能够打印选中的keys值,但是funcAllId没有值
// 点击复选框触发
nzCheck(event: NzFormatEmitEvent): void {
this.keys = event.keys || [];
this.form.patchValue({funcAllId: this.keys});
console.log(this.keys);
}
传递出去的值 ↓
HTML
<form nz-form [formGroup]="form" class="text-5">
<nz-form-item>
<nz-form-label [nzRequired]="true" [nzFor]="'funcAllID'">功能列表</nz-form-label>
<nz-form-control nzHasFeedback>
<nz-tree #nzTreeComponent *ngIf="testTree.length>0" [nzData]="testTree" nzCheckable [nzCheckedKeys]="keys"
[nzExpandedKeys]="defaultExpandedKeys"(nzCheckBoxChange)="nzCheck($event)">
</nz-tree>
</nz-form-control>
</nz-form-item>
</form>
怎么样才能给后端传递最新的keys值?
this.form.patchValue({funcAllId: this.keys});
创建表单funcAllID字段跟赋值字段funcAllId不一致,赋值不会报错,但是也不会成功