golden-layout stackCreated not available in Angular

268 Views Asked by At

I am building an app in Angular 11. I am unable to bind sackCreated event, please let me know if its deprecated or it has some alternative. Below is my code.

 this._goldenLayout.on('stackCreated', (stack) => {
      if (stack._target._contentItems.length > 0) {
        var current = this;
        var filterPopIcon: JQuery = $('<i class="pi pi-filter" id="filterPopIcon" style="margin-top:3px;margin-left:2px;cursor:pointer"/>');
        filterPopIcon.off().on('click', function () {
         
          if (stack._target._activeComponentItem._container._state.length > 2) {
            current.hierarchyService.goldenLayoutChanged.next(stack._target._activeComponentItem._container._state[0])
          }
        })
        var elementCounter: Element = filterPopIcon.get(0);
        stack._target._header.controlsContainer.prepend(elementCounter);
      }

    });

I am unable to find this event in index.d.ts file as well.Getting this error Argument of type '"stackCreated"' is not assignable to parameter of type '"hide" | "show" | "closed" | "open" | "blur" | "close" | "drag" | "focus" | "resize" | "shown" | "tab" | "__all" | "activeContentItemChanged" | "destroy" | "dragStart" | "dragStop" | ... 16 more ... | "userBroadcast"'

2

There are 2 best solutions below

1
Michael Mrozek On

This event was removed in Golden Layout 2. Instead use itemCreated and check if the event's target is a Stack:

this._goldenLayout.on('itemCreated', e => {
    if(e.target.isStack) {
        ...
    }
});
0
Milos On

Set e as any:

this._goldenLayout.on('itemCreated', (e:any) => {
      if (e.target.isStack) {
       ...
      }
    })