import { Component, ElementRef, Inject, Input, OnInit, ViewChild } from '@angular/core'; import { NB_DOCUMENT, NB_WINDOW } from '@nebular/theme'; @Component({ selector: 'ngd-akveo-services-banner', template: ` Services on Angular `, styleUrls: ['akveo-services-banner.component.scss'], }) export class AkveoServicesBanner implements OnInit { @Input() ctaId: string; @Input() width: string; @Input() height: string; @ViewChild('wrapper', { static: true }) wrapper: ElementRef; constructor(private host: ElementRef, @Inject(NB_DOCUMENT) private document, @Inject(NB_WINDOW) private window) { } ngOnInit() { if (this.window?.hbspt?.cta?.load) { this.loadCta(); } else { this.loadHubSpotCtaScript(); } } private loadCta() { this.window.hbspt.cta.load(2452262, this.ctaId, {}); } private loadHubSpotCtaScript() { this.wrapper.nativeElement.appendChild( this.document.createRange().createContextualFragment( `` ) ); this.wrapper.nativeElement.querySelector('script').onload = this.loadCta.bind(this); } }