首页 > 解决方案 > 输入“客户 | 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);
     });
  } 

标签: angularfirebase

解决方案


推荐阅读