我正在研究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;
}
@Injectable()
export class UpdateRoleClaimCommand extends BaseCommand<boolean> {
public data = RoleClaimEntryDataModel;
initialise(): void {
super.setBody(this.data);
}
}
@Injectable()
export class PermissionDataService{
constructor(
private updateRoleClaimCommand: UpdateRoleClaimCommand
){}
public UpdateRoleClaimById(roleClaimEntryDataModel: RoleClaimEntryDataModel)
{
this.updateRoleClaimCommand.data = roleClaimEntryDataModel; // throw error here
}
答案 0 :(得分:2)
因为您的data
中的UpdateRoleClaimCommand
属性是指类型RoleClaimEntryDataModel
,而不是类型RoleClaimEntryDataModel
的变量
应该是这样
@Injectable()
export class UpdateRoleClaimCommand extends BaseCommand<boolean> {
public data: RoleClaimEntryDataModel;
initialise(): void {
super.setBody(this.data);
}
}