错误TypeError:control.registerOnChange不是一个函数 [英] ERROR TypeError: control.registerOnChange is not a function

查看:247
本文介绍了错误TypeError:control.registerOnChange不是一个函数的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在html角色中的显示权限有问题.我的html代码是这样的:

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"
        },.......]

我的tscode

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

//用html填充我的表单.此刻,我的问题只是sp_id不在html中显示.名称和活动都可以. 错误是:control.registerOnChange不是函数

// 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?

推荐答案

patchValue()接受key-valueformControlName: any的对象. 您的情况是,用下面的代码行替换最后的分配:

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.

这篇关于错误TypeError:control.registerOnChange不是一个函数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆