Not getting filter data when using activatedroute paramMap

Hey there,

I am receiving the following error:
errir

Model ts file:

export interface AvailableRoom {
  BedNo: string;
  CreatedAt: string;
  Message: string;
  Name: string;
  NotificationId: string;
  Title: string;
}

export interface Notification {
  BedNo: string;
  CreatedAt: string;
  Message: string;
  Name: string;
  NotificationId: string;
  Title: string;
}

I am trying to retrieve the following filtered data by passing the following id from the paramMap in the service file when after routing.

Notification-details ts page:

export class NotificationDetailPage implements OnInit {
Notification: Notification[];
  constructor(private activatedRoute: ActivatedRoute, private retrievedata: RetrieveDataService ) { }

  ngOnInit() {


    this.activatedRoute.paramMap.subscribe(paramMap => {


      if(!paramMap.has('roomid')){
        return;
      }
      const roomid = paramMap.get('roomid');

     this.Notification = this.retrievedata.GetRoomId(roomid);

     console.log(this.Notification);



    });
  }

My service ts file:

JWTToken: string;
  httpHeaders: HttpHeaders;
  Availableroom: AvailableRoom[];
  Notification: Notification[];
  AddedNotification: Notification[];

  GetPatientBedNo(){


    Auth.currentAuthenticatedUser().then(user => {

      this.JWTToken = user.signInUserSession.accessToken.jwtToken;

      this.httpHeaders = new HttpHeaders({
        Authorization: this.JWTToken
    });

    this.http.get<any>('https://2nkjq83td2.execute-api.ap-southeast-1.amazonaws.com/support/notifications', {headers: this.httpHeaders}).subscribe(data => {


        data.sort((a,b) => {
          if(a.CreatedAt < b.CreatedAt){
            return 1;
          } else {
            return -1;
          }
        }

        );

      this.Notification = data;

        var tempBedNo = []
       this.Availableroom = data.filter(item => {
          if (!tempBedNo.includes(item.BedNo)) {
            tempBedNo.push(item.BedNo);
            return true;
          }
          else {
            return false;
          }
        })


    })

  });

  }

  GetRoomId(roomid: string){

    {
      return [...this.Notification.filter(notification => {
        return notification.BedNo == roomid;
      })];
    }
  }

}

change into

 Notification: Notification[]=[]

So at least this variable at least has a value so the filter function does not fail in case it is invoked without you expecting.

Ya you are right, but apparently i am getting an empty array value. It seems that it would sent an empty value to my components page right before getting the data from the api request.

itis pretty certain that ngOnit runs earlier than expected. If you like to wait for things, then move to other lifecycle hook, or use BehaviorSubject to emit and use filter rxjs to wait and subscribe/receive.