0

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 Answer 1

2

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.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.