shalugin / horizontal-timeline

Horizontal Timeline Component on Angular2
MIT License
39 stars 22 forks source link

unable to load data #10

Open bobingham opened 6 years ago

bobingham commented 6 years ago

I have a problem loading data. I fire the loadTimeline method after I have received data from the server. If I build the TimelineElement array manually everything works fine. If I load by pushing new objects into the array I get the following error:

ERROR TypeError: Failed to execute 'getComputedStyle' on 'Window': parameter 1 is not of type 'Element'.

  loadTimeline(carePlanSections: NcCarePlanDto[]) {
    this.timeline = [];
    setTimeout(() => { // simulate delay 
      carePlanSections.forEach((section) => {
        this.timeline.push({ caption: 'fromNow', date: moment(section.reviewDatetime).toDate(), selected: false, title: section.subject, content: section.editor })
      })
    //   this.timeline = [
    //     { caption: '16 Jan', date: moment(carePlanSections[0].createdDatetime).toDate(), title: 'Horizontal Timeline', content: this.content },
    //     { caption: '28 Feb', date: new Date(2014, 2, 28), title: 'Status#1', content: this.content },
    //     { caption: '20 Mar', date: new Date(2014, 3, 20), selected: true, title: 'Status#2', content: this.content },
    //     { caption: '20 May', date: new Date(2014, 5, 20), title: 'Status#3', content: this.content },
    //     { caption: '09 Jul', date: new Date(2014, 7, 9), title: 'Status#4', content: this.content },
    //     { caption: '30 Aug', date: new Date(2014, 8, 30), title: 'Status#5', content: this.content },
    //     { caption: '15 Sep', date: new Date(2014, 9, 15), title: 'Status#6', content: this.content },
    //     { caption: '01 Nov', date: new Date(2014, 11, 1), title: 'Status#7', content: this.content },
    //     { caption: '10 Dec', date: new Date(2014, 12, 10), title: 'Status#8', content: this.content },
    //     { caption: '29 Jan', date: new Date(2015, 1, 19), title: 'Status#9', content: this.content },
    //     { caption: '3 Mar', date: new Date(2015, 3, 3), title: 'Status#9', content: this.content },
    //   ];
    }, 2000);
  }
bobingham commented 6 years ago

My bad, One element in the array must be selected. Not quite clear on the instructions!

  loadTimeline(carePlanSections: NcCarePlanDto[]) {
    this.timeline = [];
      let selected = false;
      carePlanSections.forEach((section, key, arr) => {
        if (Object.is(arr.length - 1, key)) {
          selected = true; // execute last item logic
        }
       this.timeline.push({ caption: section.subject, date: moment(section.reviewDatetime).toDate(), title: section.subject, selected: selected, content: section.editor })
      })
  }