angular - 输入“客户 | undefined' 不能分配给使用 angular12 和 firebase 的类型 'Client'
问题描述
我创建了一个允许显示客户端的客户端管理应用程序,并且我为每个客户端都有一个详细信息按钮来显示客户端的详细信息,所以我想检索客户端的详细信息,但我给出了错误:Type 'Client | undefined 'is not assignable to type' Client '
. 视觉代码在它上面加了下划线this.client = client;
客户端服务.ts
getClient(id:string) {
return this.clientsCollection.doc(id).valueChanges();
}
模型客户
export interface Client{
id? : string,
firstname? : string,
lastname? : string,
email? : string,
phone? : number,
balance : number
}
详细信息-client.component.ts
ngOnInit(): void {
this.id = this.router.snapshot.params['id'];
this.clientService.getClient(this.id).subscribe(client => {
this.client = client;
console.log(this.client);
});
}
解决方案
推荐阅读
- laravel - 缺少路线 5.6 所需的参数
- angular - 从 API 中选择选项数据源
- java - 无法将 JSON 值反序列化为类型
- vba - 用于导出/复制粘贴到单独工作簿的 Excel 宏
- git - 使用 git merge / git merge-base,可靠地确定分支是否是功能分支
- laravel-5 - 在 Eloquent 中返回和访问 JSON 字段
- java - The minSdk version should not be declared in the android manifest file
- java - 应用程序编译得很好而不是错误,但然后在按钮单击时中断。可能与背景颜色变化有关
- javascript - 在 Chrome 上更改具有 src="about:blank" 的 iframe 内容的 CSS
- python - 如何在python中检查其中包含制表符的列表?