ERROR TypeError: control.registerOnChange is not a

2020-02-16 01:28发布

I have a problem with display permission in role in html. My html code like this:

  <div class="row">
    <select multiple formControlName="sp_id" id="permission_id" materialize="material_select" [materializeSelectOptions]="permissions">
      <option value="" disabled selected>Select Permissions</option>
      <option *ngFor="let permission of permissions" [value]="permission.permission_id">{{permission.permissin_desc}}</option>
    </select>
  </div>

json

{
    "StatusCode": 0,
    "StatusMessage": "OK",
    "StatusDescription": [
        {
            "permission_id": 1,
            "permission_desc": "getallclient"
        },
        {
            "permission_id": 2,
            "permission_desc": "createclient"
        },
        {
            "permission_id": 3,
            "permission_desc": "deleteclient"
        },
        {
            "permission_id": 4,
            "permission_desc": "updateclient"
        },.......]

my tscode

  this.editclientForm = this.fb.group({
      'name': new FormControl('', Validators.required),
      'active': new FormControl('', Validators.required),
      'sp_id': this.fb.array([])
    });

// populate my form in html. At the moment, my problem is only sp_id that dosn't show in html. Name and active are ok. Error is: control.registerOnChange is not a function

 populateClientRole() {
    this.activatedRoute.params.subscribe(
      params => {
        this.rs.getRoleById(params['id']).subscribe(
          role => {
            this.role = role;
            this.editclientForm.controls['name'].setValue(role.name);
            this.editclientForm.controls['active'].setValue(role.active);
            this.editclientForm.controls['sp_id'].patchValue(role.sp_id);
             }
        );
      }
    );
  }

Can you suggest me, what is the problem please?

1条回答
趁早两清
2楼-- · 2020-02-16 02:01

patchValue() takes an object of key-value pairs of formControlName: any. In your case, replace the last assignment with below line of code:

this.editclientForm.patchValue({sp_id: role.sp_id});

Hope, this will fix your issue.

查看更多
登录 后发表回答