0

How to use modals in Angular Universal? Toasts, dropdowns - all stuff that works with DOM and us library js?

I have the problem with implementing code

import { Toast } from '../../../../../node_modules/bootstrap/dist/js/bootstrap.min.js'
import {DOCUMENT, isPlatformBrowser} from "@angular/common";
  
export class ToastComponent implements OnInit, AfterViewInit {
  @ViewChild('toast') toast: ElementRef<HTMLDivElement>

  constructor(@Inject(PLATFORM_ID) private platformId: Object,
              @Inject(DOCUMENT) private _doc: Document) {

    if (isPlatformBrowser(this.platformId)) {

      console.log('getWindow', this.getWindow())
      console.log('this.getWindow().document', this.getWindow().document)
      
      // var toastElList = [].slice.call(document.querySelectorAll('.toast'))
      // var toastList = toastElList.map(function (toastEl) {
        return new bootstrap.Toast(this.toast, {}) //error in this 1 variant
      // })


      // Array.from([this.toast])
        // .forEach(toastNode => new Toast(toastNode))

      return new Toast(this.toast); //error in this 2 variant


    }
  }


  getWindow(): Window | null {
    return this._doc.defaultView;
  }

}
Tatyana Molchanova
  • 1,305
  • 5
  • 12
  • 23

1 Answers1

0

Any variants of installing and working with Bootstrap (latest, @types) didn't work for me.

I installed Angular Material and use it SnackBar and it works fine.

https://material.angular.io/components/snack-bar/examples

I delete Bootstrap from Angular Universal as a nightmare. 3 days spent for nothing.

Tatyana Molchanova
  • 1,305
  • 5
  • 12
  • 23