Angular2从方法参数对象

时间:2018-07-30 10:56:24

标签: angular typescript

我正在研究Angular 5应用程序。我有模型类RoleClaimEntryDataModel,在一个可注入服务中,我有方法'UpdateRoleClaimById',接收RoleClaimEntryDataModel作为参数,我试图将此对象分配给类的RoleClaimEntryDataModel,但出现错误

错误

Type 'RoleClainEntryDataModel' is not assignable to type 'typeof RoleClaimEntryDataModel'/
Property 'prototype' is missing in type 'RoleClaimEntryDataModel'

模型类

export class RoleClaimEntryDataModel{
  roleId:string;
  claimId:string;
  isClaimAssignToRole:boolean;
}

可注射服务A

 @Injectable()
 export class UpdateRoleClaimCommand extends BaseCommand<boolean> {

  public data = RoleClaimEntryDataModel;

  initialise(): void {
      super.setBody(this.data);
  }
}

可注射服务B

@Injectable()
export class PermissionDataService{

constructor(
    private updateRoleClaimCommand: UpdateRoleClaimCommand
){}

 public UpdateRoleClaimById(roleClaimEntryDataModel: RoleClaimEntryDataModel)
{
    this.updateRoleClaimCommand.data = roleClaimEntryDataModel; // throw error here
}

1 个答案:

答案 0 :(得分:2)

因为您的data中的UpdateRoleClaimCommand属性是指类型RoleClaimEntryDataModel,而不是类型RoleClaimEntryDataModel的变量

应该是这样

@Injectable()
 export class UpdateRoleClaimCommand extends BaseCommand<boolean> {

  public data: RoleClaimEntryDataModel;

  initialise(): void {
      super.setBody(this.data);
  }
}