angular - “别名”类型的参数不可分配给“任何 []”类型的参数
问题描述
当我现在更新角度版本时,我遇到了主题中的错误。我应该如何解决这个问题?
我的界面如下:
export interface Alias {
nr?: number;
local_part?: string;
domain?: string;
recipients?: string;
username?: string;
changes?: string;
action?: string;
old_alias?: string;
}
在我的 component.ts
export class HomeComponent implements OnInit {
alias: Alias
我想从后端获取数据
this.aliasesService.getAlias(params).subscribe(
res => {
var result = Object.keys(res).map(function (key) {
return [Number(key), res[key]];
});
this.alias = res;
},
err => console.error(err)
);
有错误信息
ERROR in src/app/home/home.component.html:154:44 - error TS2345: Argument of type 'Alias' is not assignable to parameter of type 'any[]'.
Type 'Alias' is missing the following properties from type 'any[]': length, pop, push, concat, and 26 more.
154 *ngFor="let aliases of alias | filterBy: queryString | paginate: { itemsPerPage: 10, currentPage: p }; let i = index">
解决方案
这可能会发生,因为在您的服务中,您将返回设置为Observable<any[]>
,而不是数组,删除括号,然后它将是这样的:
Observable<any>
推荐阅读
- android - 如何用重力平均分配线性布局项目
- python - 通过 pyodbc 更新 Oracle DB 挂起
- android - Android工作室的在线数据库
- sql - postgres 数组到列的数组
- php - 会话用户数据无法使用 curl 获取数据
- mysql - MySQL 根据 varchar 字段的首字母进行分区
- php - 在 App\Http\Controllers\Controller.php [Laravel] 中包含共享方法
- c# - 有没有办法从所有类型的文件中提取所有元数据?
- azure - 数据库和 Azure 队列触发器:如何防止同时访问数据库资源
- python-3.x - TensorFlow 梯度示例