Forms and Angular

Well, I hope you might have already figured this out. But this might be helpful for people who are looking further. I had the same requirement and this is how I did it and it’s working perfectly.

In Index.html:
< script charset=“utf-8” type=“text/javascript” src=“https://js.hsforms.net/forms/shell.js”>

In Template:
< div id=“hubspotForm”>

In Component:

declare var hbspt: any // put this at the top

ngAfterViewInit(){
hbspt.forms.create({
portalId: “[YOUR-PORTAL-ID]”,
formId: “[YOUR-FORM-ID]”,
target: “#hubspotForm
});
window.scrollTo(0, 0); // used this because the scroll position is not at the top after inserting the form, so i’m manually pushing it
wink.png

}

Cheers