Angular 错误:未捕获(承诺中):类型错误:无法读取属性';状态';空的

Angular 错误:未捕获(承诺中):类型错误:无法读取属性';状态';空的,angular,typescript,Angular,Typescript,我正在尝试将票证的JSON结果从打开过滤到关闭,并且正在进行中,JSON数据从api正确返回,并保存在totalTicketsDataMain变量中。但每当我尝试过滤数据时,存储openTicketsData的变量就会在mozilla上抛出错误 电话号码是98 this.openTicketsData = this.totalTicketsDataMain.filter(x => (x.status === "Open" || x.status === "In

我正在尝试将票证的JSON结果从打开过滤到关闭,并且正在进行中,JSON数据从api正确返回,并保存在
totalTicketsDataMain
变量中。但每当我尝试过滤数据时,存储
openTicketsData
的变量就会在mozilla上抛出错误

电话号码是98

this.openTicketsData = this.totalTicketsDataMain.filter(x => (x.status === "Open" || x.status === "In Progress")); //line 98
我不确定我遗漏了什么或做错了什么这是我的TicketlistComponent

openTicketsData: Ticket[];
  totalTicketsDataMain: Ticket[];

status = "Open";
 async ngOnInit(): Promise<void> {
       await this.getTicketsData();
  }

 async getTicketsData(): Promise<void> {
    this.totalTicketsDataMain = await this.ticketService.getTickets(this.currentProjectId);
    if (this.teamId && this.eaId && this.householdId) {
      this.totalTicketsDataMain = this.totalTicketsDataMain.filter(x => x.eaId == this.eaId && x.householdId == this.householdId && x.teamId == this.teamId && x.status == this.status);
    }

    if (this.totalTicketsDataMain) {
      this.openTicketsData = this.totalTicketsDataMain.filter(x => (x.status === "Open" || x.status === "In Progress")); //line 98
      this.inProgressTicketsData = this.totalTicketsDataMain.filter(x => (x.status === "In Progress"));
      this.closedTicketsData = this.totalTicketsDataMain.filter(x => (x.status === "Closed"));
      let user =  this.userSessionService.getSession('usersession') as UserSession;
      this.assaignedToMeTicketsData = this.totalTicketsDataMain.filter(x => x.assignedTo == user.emailId);
      this.createdByMeTicketsData = this.totalTicketsDataMain.filter( x=> x.createdBy == user.emailId);
    }

    if (this.teamId == undefined  || this.eaId == undefined || this.householdId == undefined) {
      this.totalTicketsData = this.totalTicketsDataMain.filter(x => x.status == "Open" || x.status == "In Progress");
    }


  }
openTicketsData:Ticket[];
totalTicketsDataMain:票证[];
status=“打开”;
异步ngOnInit():承诺{
等待此消息。getTicketsData();
}
异步getTicketsData():承诺{
this.totalTicketsDataMain=等待this.ticketService.getTickets(this.currentProjectId);
if(this.teamId&&this.eaId&&this.householdId){
this.totalTicketsDataMain=this.totalTicketsDataMain.filter(x=>x.eaId==this.eaId&&x.householdId==this.householdId&&x.teamId==this.teamId&&x.status==this.status);
}
if(this.totalTicketsDataMain){
this.openTicketsData=this.totalTicketsDataMain.filter(x=>(x.status==“打开”| | x.status==“正在进行”);//第98行
this.inProgressTicketsData=this.totalTicketsDataMain.filter(x=>(x.status==“进行中”);
this.closedTicketsData=this.totalTicketsDataMain.filter(x=>(x.status==“Closed”);
让user=this.userSessionService.getSession('usersession')作为usersession;
this.assignedtometicketsdata=this.totalTicketsDataMain.filter(x=>x.assignedTo==user.emailId);
this.createdByMeTicketsData=this.totalTicketsDataMain.filter(x=>x.createdBy==user.emailId);
}
if(this.teamId==未定义| | this.eaId==未定义| | this.householdId==未定义){
this.totalTicketsData=this.totalTicketsDataMain.filter(x=>x.status==“打开”| | x.status==“进行中”);
}
}
取票服务功能

async getTickets(projectId: string): Promise<Ticket[]> {
        try {
            const url = ServiceConstants.apiUrl + `/tickets/getticketlist?projectId=${projectId}`;
            let response = await this.httpService.get(url, { headers: this.getHeaders() }).toPromise();
            return response as Ticket[];
        } catch (error) {
            this.handleError(error);
        }
    }
异步getTickets(projectd:string):Promise{ 试一试{ 常量url=ServiceConstants.apiUrl+`/tickets/getticketlist?projectId=${projectId}`; 让response=wait this.httpService.get(url,{headers:this.getHeaders()}).toPromise(); 返回响应作为票证[]; }捕获(错误){ 此.handleError(错误); } }

如果前两个If条件不符合,则this.totalTicketsDataMain将保持为空。尝试获取此.totalTicketsData将是不可能的。此外,如果没有遵循所有条件,则没有状态设置为打开。
在此处输入code

因为
x
为null,并且null没有
状态
属性,您必须调试并找出为什么在loopHi@Rumjhum Singru中x变为null我不明白您的意思。totalTicketsDataMain为null,这不是您的if条件已满足的情况。@arriff但当我做控制台日志时,它有数据,
this.totalTicketsDataMain=wait this.ticketService.getTickets(this.currentprojectd);console.log(“data is thre”,this.totalTicketsDataMain)
,它打印数据您介意在第98行显示您的控制台日志吗,就在筛选之前。如果共享,数据可用
openTicketsData: Ticket[];
  totalTicketsDataMain: Ticket[];

status = "Open";
 async ngOnInit(): Promise<void> {
       await this.getTicketsData();
  }

 async getTicketsData(): Promise<void> {
    this.totalTicketsDataMain = await this.ticketService.getTickets(this.currentProjectId);
    if (this.teamId && this.eaId && this.householdId) {
      this.totalTicketsDataMain = this.totalTicketsDataMain.filter(x => x.eaId == this.eaId && x.householdId == this.householdId && x.teamId == this.teamId && x.status == this.status);
    }

    if (this.totalTicketsDataMain) {
      this.openTicketsData = this.totalTicketsDataMain.filter(x => (x.status === "Open" || x.status === "In Progress")); //line 98
      this.inProgressTicketsData = this.totalTicketsDataMain.filter(x => (x.status === "In Progress"));
      this.closedTicketsData = this.totalTicketsDataMain.filter(x => (x.status === "Closed"));
      let user =  this.userSessionService.getSession('usersession') as UserSession;
      this.assaignedToMeTicketsData = this.totalTicketsDataMain.filter(x => x.assignedTo == user.emailId);
      this.createdByMeTicketsData = this.totalTicketsDataMain.filter( x=> x.createdBy == user.emailId);
    }

    if (this.teamId == undefined  || this.eaId == undefined || this.householdId == undefined) {
      this.totalTicketsData = this.totalTicketsDataMain.filter(x => x.status == "Open" || x.status == "In Progress");
    }


  }
async getTickets(projectId: string): Promise<Ticket[]> {
        try {
            const url = ServiceConstants.apiUrl + `/tickets/getticketlist?projectId=${projectId}`;
            let response = await this.httpService.get(url, { headers: this.getHeaders() }).toPromise();
            return response as Ticket[];
        } catch (error) {
            this.handleError(error);
        }
    }