Skip to content

[Angular] How to give a component variable the value of a clicked item #357

Closed
@Dako390

Description

Your question and description of the problem goes here
How can give my variable the value of an item I clicked on? I can't use classwide varibales with this. inside of the action function. I want to display an item's properties, e.g. label, color, time, inside of another html element. In my case I want to set the variable selectedTimeslot to the item that has been clicked on.

Code
You can paste your code and data examples here if it will help to answer the question.

// the timeslot the user clicked one; the interface TimeSlot looks like this:
// https://gantt-schedule-timeline-calendar.neuronet.io/documentation/configuration/chart/items
public selectedTimeslot: TimeSlot = {} as TimeSlot;

public clickAction(element: any, data: any) {
    function onClick(event: any) {
      console.log(data.item); 
      console.log(GSTC.api.sourceID(data.item.id));
    }

    element.addEventListener('click', onClick);

    return {
      update(element: any, newData: any) {
        data = newData;
      },

      destroy(element: any, data: any) {
        element.removeEventListener("click", onClick);
      },
    };
  }
  
  // somewhere in the config
  const config = {
  /* ... */
  actions: {
    'chart-timeline-items-row-item': [this.clickAction],
  },
  /* ... */
};

Now I want public selectedTimeslot to be data.item - how can I achieve that?

Thanks a lot in advance!

Metadata

Assignees

No one assigned

    Labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions