Skip to content

Commit 911286b

Browse files
committed
feat(ivy): add partial IVY support for *axLazyElement directive
- unfortunately does NOT yet work with *axLazyElementDynamic directive
1 parent 6d9a17e commit 911286b

File tree

2 files changed

+16
-7
lines changed

2 files changed

+16
-7
lines changed

projects/elements/src/lib/lazy-elements/lazy-element-dynamic/lazy-element-dynamic.directive.ts

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -59,13 +59,19 @@ export class LazyElementDynamicDirective implements OnInit {
5959
this.elementsLoaderService
6060
.loadElement(this.url, this.tag, this.isModule)
6161
.then(() => {
62-
const host = (this.template as any)._def.element.template.nodes[0]
63-
.element;
64-
host.name = this.tag;
62+
if ((this.template as any)._declarationTContainer) {
63+
// (this.template as any)._declarationTContainer.tagName = this.tag;
64+
throw new Error(
65+
'The *axLazyElementDynamic directive is currently does NOT support Angular Ivy, please use standard *axLazyElement directive instead!'
66+
);
67+
} else {
68+
(this
69+
.template as any)._def.element.template.nodes[0].element.name = this.tag;
70+
}
6571
this.vcr.clear();
6672
this.vcr.createEmbeddedView(this.template);
6773
})
68-
.catch(() => {
74+
.catch(error => {
6975
const errorComponent =
7076
elementConfig.errorComponent || options.errorComponent;
7177
this.vcr.clear();
@@ -76,7 +82,8 @@ export class LazyElementDynamicDirective implements OnInit {
7682
this.vcr.createComponent(factory);
7783
} else {
7884
console.error(
79-
`${LOG_PREFIX} - Loading of element <${this.tag}> failed, please provide <ng-template #error>Loading failed...</ng-template> and reference it in *axLazyElementDynamic="errorTemplate: error" to display customized error message in place of element`
85+
`${LOG_PREFIX} - Loading of element <${this.tag}> failed, please provide <ng-template #error>Loading failed...</ng-template> and reference it in *axLazyElementDynamic="errorTemplate: error" to display customized error message in place of element\n\n`,
86+
error
8087
);
8188
}
8289
});

projects/elements/src/lib/lazy-elements/lazy-element/lazy-element.directive.ts

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,8 +31,10 @@ export class LazyElementDirective implements OnInit {
3131
) {}
3232

3333
ngOnInit() {
34-
const elementTag = (this.template as any)._def.element.template.nodes[0]
35-
.element.name;
34+
const tpl = this.template as any;
35+
const elementTag = tpl._declarationTContainer
36+
? tpl._declarationTContainer.tagName
37+
: tpl._def.element.template.nodes[0].element.name;
3638

3739
const elementConfig =
3840
this.elementsLoaderService.getElementConfig(elementTag) ||

0 commit comments

Comments
 (0)