Skip to content

Commit

Permalink
fix(elements): fix binding issue
Browse files Browse the repository at this point in the history
Fix binding issue when using element in a parent Angular application.
Binding issue occured due to a race condition between browser parsing
and executing script and Angular trying to create the view from the template.
  • Loading branch information
gshokanov committed May 18, 2020
1 parent 54fc6db commit 2dcf755
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,7 @@ export class LazyElementDynamicDirective implements OnInit {

this.elementsLoaderService
.loadElement(this.url, this.tag, this.isModule, elementConfig?.hooks)
.then(() => customElements.whenDefined(this.tag))
.then(() => {
this.vcr.clear();
const originalCreateElement = this.renderer.createElement;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,7 @@ describe('LazyElementDirective', () => {
let testHostComponent: TestHostComponent;
let fixture: ComponentFixture<TestHostComponent>;
let appendChildSpy: jasmine.Spy;
let whenDefinedSpy: jasmine.Spy;

beforeEach(async(() => {
TestBed.configureTestingModule({
Expand All @@ -104,6 +105,9 @@ describe('LazyElementDirective', () => {
fixture = TestBed.createComponent(TestHostComponent);
testHostComponent = fixture.componentInstance;
appendChildSpy = spyOn(document.body, 'appendChild').and.stub();
whenDefinedSpy = spyOn(customElements, 'whenDefined').and.returnValue(
Promise.resolve()
);
fixture.detectChanges();
});

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@ export class LazyElementDirective implements OnInit {
}
this.elementsLoaderService
.loadElement(this.url, elementTag, this.isModule, elementConfig?.hooks)
.then(() => customElements.whenDefined(elementTag))
.then(() => {
this.vcr.clear();
this.vcr.createEmbeddedView(this.template);
Expand Down

0 comments on commit 2dcf755

Please sign in to comment.