Having trouble setting an array property in angular 6 using the following code:
this.addupdate.roleids=this.selectedRole;
An error is being thrown:
ERROR TypeError: Cannot set property 'roleids' of undefined at AccessLevelComponent.push../src/app/admin/admin/dashboard/role/access-level/access-level.component.ts.AccessLevelComponent.AddRoleClaim (access-level.component.ts:60)
selectedRole:string[]=['1011','1010','1005'];
Here's my interface definition:
export interface IAddorupdateRole {
roleids:string[];
roleid:number;
}
And here's part of my code:
public AddRoleClaim(){
console.log("enter AddRoleClaim.Ts");
this.addupdate.roleids=this.selectedRole;
this.addupdate.roleid=this.roleId;
this.roleService.AddOrUpdateRoleCalim(this.addupdate).subscribe((data)=>
{
console.log("success" + data);
}
);
}
What could be causing this issue? How can I resolve it?