import connectResizer from "@iframe-resizer/core"
export type iframeResizerObject = {
moveToAnchor: (anchor: string) => void
sendMessage: (message: string, targetOrigin?: string) => void
type iframeResizerObjectPrivateMethods = {
type iframeResizerObjectPrivate = iframeResizerObject &
iframeResizerObjectPrivateMethods
export interface iframeResizerElement extends HTMLIFrameElement {
iFrameResizer: iframeResizerObject
export type iframeResizerOptions = {
bodyBackground?: string | null
bodyMargin?: string | number | null
bodyPadding?: string | number | null
checkOrigin?: boolean | string[]
direction?: "vertical" | "horizontal" | "none"
scrolling?: boolean | "omit"
selector: "[iframe-resizer]",
export class IframeResizerDirective {
private resizer?: iframeResizerObjectPrivate
@Output() onReady = new EventEmitter<iframeResizerElement>()
@Output() onClose = new EventEmitter<iframeResizerElement>()
@Output() onMessage = new EventEmitter<{
iframe: iframeResizerElement
@Output() onMouseEnter = new EventEmitter<{
iframe: iframeResizerElement
@Output() onMouseLeave = new EventEmitter<{
iframe: iframeResizerElement
@Output() onResized = new EventEmitter<{
iframe: iframeResizerElement
@Output() onScroll = new EventEmitter<{
iframe: iframeResizerElement
get iframeResizer(): iframeResizerObject | undefined {
@Input() options: iframeResizerOptions = {
constructor(private elementRef: ElementRef) {}
ngAfterViewInit(): void {
this.resizer = connectResizer({
onClose: (iframeID: any) => {
`[iframe-resizer/angular][${this.elementRef.nativeElement?.id}] Close event ignored, to remove the iframe update your Angular component.`
onMessage: (event: { iframe: iframeResizerElement message: string }) =>
this.onMessage.next(event),
iframe: iframeResizerElement
}) => this.onMouseEnter.next(event),
iframe: iframeResizerElement
}) => this.onMouseLeave.next(event),
onReady: (iframe: iframeResizerElement) => this.onReady.next(iframe),
iframe: iframeResizerElement
}) => this.onResized.next(event),
iframe: iframeResizerElement
}) => this.onScroll.next(event),
})(this.elementRef.nativeElement)
this.resizer?.disconnect()
public moveToAnchor(anchor: string) {
this.resizer?.moveToAnchor(anchor)
public sendMessage(message: string, targetOrigin?: string) {
this.resizer?.sendMessage(message, targetOrigin)