angular7 类型 'Observable <Object>' 不能分配给类型 'Observable <Grupo> []
angular7 the type 'Observable <Object>' cannot be assigned to the type 'Observable <Grupo> []
将可观察对象分配给 class 时出现此错误:
无法将类型 'Observable ' 分配给类型 'Observable <Grupo []>'。类型 'Object' 没有类型 'Grupo []' 的以下属性:length、pop、push、concat
界面
export interface Grupo {
id?: number;
exames:Exames[];
anexos: Anexos[];
nome: string;
descr: string;
data: string;
receita: string;
data_sis:string;
ver: string;
cod_app: number;
cliente: number;
}
服务
getGrupoExame():Observable<Grupo[]> {
return this.http.get<Grupo[]>(this.apiRoot)
.pipe(
delay(1500)
)
}
组件
grupo$: Observable<Grupo[]>;
this.grupo$ = this.apiExames.getGrupoExames();
正如@Mike One 所说,这只是缺乏关注,因为他声明了两个名称相似的方法。 observable 工作正常。
将可观察对象分配给 class 时出现此错误:
无法将类型 'Observable ' 分配给类型 'Observable <Grupo []>'。类型 'Object' 没有类型 'Grupo []' 的以下属性:length、pop、push、concat
界面
export interface Grupo {
id?: number;
exames:Exames[];
anexos: Anexos[];
nome: string;
descr: string;
data: string;
receita: string;
data_sis:string;
ver: string;
cod_app: number;
cliente: number;
}
服务
getGrupoExame():Observable<Grupo[]> {
return this.http.get<Grupo[]>(this.apiRoot)
.pipe(
delay(1500)
)
}
组件
grupo$: Observable<Grupo[]>;
this.grupo$ = this.apiExames.getGrupoExames();
正如@Mike One 所说,这只是缺乏关注,因为他声明了两个名称相似的方法。 observable 工作正常。