Home » Jquery » jquery – ng-select2 dropdown still shows after clicking browser back button-Exceptionshub

jquery – ng-select2 dropdown still shows after clicking browser back button-Exceptionshub

Posted by: admin February 24, 2020 Leave a comment

Questions:

I am using an ng-select2 component here

  <ng-select2 id="supportTicketFilter" class="support-ticket-filter" width="370" [data]="filterValues"
            [options]="options" (valueChanged)="filterTable($event)" name="searchBar" data-selected="selected">
</ng-select2>

The issue is that when the drop down is selected as seen belowenter image description here

and you click the back button on the browser, the dropdown menu still appears on the next page.

enter image description here

Has anyone run into this issue before?
The only thing I can think of now is to listen for the back button on the browser and then try to toggle something in the ng-select2.

How to&Answer:

Found the solution, there was a class added on the container for the list that is rendered when clicking the dropdown.

for angular solutions was this

ngOnDestroy(): void {
    const selectOptionsContainer = $('.select2-container');
    selectOptionsContainer.removeClass('select2-container--open')
  }