Search code examples
angularsweetalert2

Angular SweetAlert2 Multi Select


I need to use ng-select directive inside SweetAlert2, the following code doesn't work:

  const { value: formValues } = await swal.fire({
    title: 'Multiple inputs',
    html:
      '<ng-select id="selectedItems" [items]="'+this._data+'" bindLabel="name"' +
      'placeholder="Items" [multiple]="true">' +
      '</ng-select>',
    focusConfirm: false,
    preConfirm: () => {
      return [
        document.getElementById('parcoursSelected').value
      ]
    }
  })

if (formValues) {
  swal.fire(JSON.stringify(formValues))
}

There are two problems:

  1. The first one: the input select is not displayed

enter image description here

  1. The second one: I don't know how to get the selected value

enter image description here

enter image description here

Thank you in advance


Solution

  • As far as I know from previous experience using sweet alert and Angular 2+, sweet alert code is injected only on button push, after which it is not recompiled through angular, and therefore you cannot add directives in your swal HTML and expect them to work.