Skip to content

Commit de86e11

Browse files
committed
feat: switch to ngOnChanges
1 parent 0677f82 commit de86e11

File tree

1 file changed

+10
-6
lines changed

1 file changed

+10
-6
lines changed

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

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,11 @@ import {
55
EmbeddedViewRef,
66
Inject,
77
Input,
8+
OnChanges,
89
OnDestroy,
910
OnInit,
1011
PLATFORM_ID,
12+
SimpleChanges,
1113
TemplateRef,
1214
ViewContainerRef,
1315
} from '@angular/core';
@@ -31,12 +33,8 @@ const LOG_PREFIX = '@angular-extensions/elements';
3133
@Directive({
3234
selector: '[axLazyElement]',
3335
})
34-
export class LazyElementDirective implements OnInit, OnDestroy {
35-
@Input('axLazyElement')
36-
set url(url: string) {
37-
this.url$.next(url);
38-
}
39-
36+
export class LazyElementDirective implements OnChanges, OnInit, OnDestroy {
37+
@Input('axLazyElement') url: string;
4038
@Input('axLazyElementLoadingTemplate') loadingTemplateRef: TemplateRef<any>; // eslint-disable-line @angular-eslint/no-input-rename
4139
@Input('axLazyElementErrorTemplate') errorTemplateRef: TemplateRef<any>; // eslint-disable-line @angular-eslint/no-input-rename
4240
@Input('axLazyElementModule') isModule: boolean | undefined; // eslint-disable-line @angular-eslint/no-input-rename
@@ -55,6 +53,12 @@ export class LazyElementDirective implements OnInit, OnDestroy {
5553
private cdr: ChangeDetectorRef
5654
) {}
5755

56+
ngOnChanges(changes: SimpleChanges): void {
57+
if (changes.url) {
58+
this.url$.next(this.url);
59+
}
60+
}
61+
5862
ngOnInit() {
5963
// There's no sense to execute the below logic on the Node.js side since the JavaScript
6064
// will not be loaded on the server-side (Angular will only append the script to body).

0 commit comments

Comments
 (0)