ultimatecourses / angular-pro-app-seed

Seed project for Angular Pro final application
112 stars 360 forks source link

Unable to retrieve $key from schedule section #10

Closed jonolo-3 closed 5 years ago

jonolo-3 commented 5 years ago

Hi, I'm getting back undefined when trying to retrieve the key for a section in schedule.service.ts. I'm on angular 7+ and rxjs 6+.

This snippet is the problem. I'm always getting id = undefined leading to that I am always going to createSection.

items$ = this.itemList$.pipe( withLatestFrom(this.section$), map(([items, section]: any[]) => {

  const id = section.data.$key;

  const defaults: ScheduleItem = {
    workouts: null,
    meals: null,
    section: section.section,
    timestamp: new Date(section.day).getTime()
  };

  const payload = {
    ...(id ? section.data : defaults),
    ...items
  };

  console.log(id);
  if (id) {
    console.log('updateSection');
    return this.updateSection(id, payload);
  } else {
    console.log('createSection');
    return this.createSection(payload);
  }
})

);