MuxForms on Angular loads embed.js in src/index.html, places data-form-id on a template ref in ContactComponent, and calls window.MuxForms.mount in ngAfterViewInit. Allow your deployed SPA origin.
Docs
Angular apps need an explicit mount after the view renders—embed.js does not guess your component lifecycle.
| Piece | Detail |
|---|---|
| index.html | defer script |
| ContactComponent | ViewChild + AfterViewInit |
| Router | Component recreated per visit |
| Allowlist | Production SPA URL |
import { AfterViewInit, Component, ElementRef, ViewChild } from "@angular/core";
@Component({
selector: "app-contact",
template: `<h1>Contact</h1><div #host data-form-id="FORM_UUID"></div>`,
})
export class ContactComponent implements AfterViewInit {
@ViewChild("host") host!: ElementRef<HTMLDivElement>;
ngAfterViewInit() {
window.MuxForms?.mount(this.host.nativeElement);
}
}<script src="https://www.muxforms.com/embed.js" defer></script>
One mount hook on the contact route.
Upgrade to Pro