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;
}
}