Manually Set Value for FormBuilder Control

前端 未结 11 1105
执笔经年
执笔经年 2020-11-27 11:25

This is driving me nuts, I\'m under the gun and can\'t afford to spend another whole day on this.

I am trying to manually set a control value (\'dept\') within the c

11条回答
  •  一个人的身影
    2020-11-27 11:51

    You could try this:

    deptSelected(selected: { id: string; text: string }) {
      console.log(selected) // Shows proper selection!
    
      // This is how I am trying to set the value
      this.form.controls['dept'].updateValue(selected.id);
    }
    

    For more details, you could have a look at the corresponding JS Doc regarding the second parameter of the updateValue method: https://github.com/angular/angular/blob/master/modules/angular2/src/common/forms/model.ts#L269.

提交回复
热议问题