Skip to content
This repository has been archived by the owner on Aug 1, 2024. It is now read-only.

Commit

Permalink
remove replacing web component in DOM on input changes
Browse files Browse the repository at this point in the history
  • Loading branch information
Piotr Bochenek committed Nov 3, 2023
1 parent db90893 commit 1ebc9d3
Showing 1 changed file with 13 additions and 12 deletions.
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
import {
Component,
ElementRef,
EventEmitter,
Input,
OnChanges,
Output
Component,
ElementRef,
EventEmitter,
Input,
OnChanges, OnInit,
Output
} from '@angular/core';
import DescopeWebComponent from '@descope/web-component';
import DescopeWc, { ILogger } from '@descope/web-component';
Expand All @@ -16,7 +16,7 @@ import { baseHeaders } from '../../utils/constants';
selector: 'descope[projectId][flowId]',
template: ''
})
export class DescopeComponent implements OnChanges {
export class DescopeComponent implements OnInit, OnChanges {
@Input() projectId: string;
@Input() flowId: string;

Expand All @@ -43,6 +43,12 @@ export class DescopeComponent implements OnChanges {
DescopeWc.sdkConfigOverrides = { baseHeaders };
this.webComponent = new DescopeWebComponent();
}

ngOnInit() {
this.setupWebComponent();
this.elementRef.nativeElement.appendChild(this.webComponent);
}

ngOnChanges(): void {
this.setupWebComponent();
}
Expand Down Expand Up @@ -100,10 +106,5 @@ export class DescopeComponent implements OnChanges {
});
}

const nativeElement = this.elementRef.nativeElement;
while (nativeElement.lastElementChild) {
nativeElement.removeChild(nativeElement.lastElementChild);
}
nativeElement.appendChild(this.webComponent);
}
}

0 comments on commit 1ebc9d3

Please sign in to comment.