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?
patchValue()
takes an object ofkey-value
pairs offormControlName: any
. In your case, replace the last assignment with below line of code:Hope, this will fix your issue.