mardi 27 février 2018

Using a value from Component in Template hosting Component

I have a stacked bar chart component that on click, records the three values of the 'stack' and allows me to print them in the component template.

I would like to use these values in the parent template that is hosting the component but I am not sure how to send his data 'up'. I attempted to follow the proceedure in this question but I couldn't get it to work. I have also been unable to diagnose why this solution doesn't work as I receive no console or build errors.

My code is below:

Relevant Component Code:

.on('click', d => {
        let clickedLabel = d.data.label;
        let clickedCount1 = d.data.count1;
        let clickedCount2 = d.data.count2;
        let clickedCount3 = d.data.count3;

        if (this.get('on-click')) {
          this.get('on-click')(clickedLabel);
          this.set('selectedCount1', clickedCount1);
          this.set('selectedCount2', clickedCount2);
          this.set('selectedCount3', clickedCount3);

        } else {
          if (clickedLabel === this.get('selectedLabel')) {
            this.set('selectedLabel', '');
            this.set('selectedCount', '');
          } else {
            this.set('selectedLabel', clickedLabel);
            this.set('selectedCount1', clickedCount1);
            this.set('selectedCount2', clickedCount2);
            this.set('selectedCount3', clickedCount3);

          }

Component in template:



There is currently no relevant code in the controller for the parent template.




Aucun commentaire:

Enregistrer un commentaire