Skip to content

Instantly share code, notes, and snippets.

@bob-lee
Last active November 2, 2018 22:12
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save bob-lee/6a4b3373e9b174947b0ccf1b8aaf446b to your computer and use it in GitHub Desktop.
Save bob-lee/6a4b3373e9b174947b0ccf1b8aaf446b to your computer and use it in GitHub Desktop.
export class LazyLoadDirective implements AfterViewInit, OnDestroy {
private _url = '';
@Input()
set url(value: string) { // optional
if (!this._url && value) { // url added runtime
this.doRegister();
}
this._url = value;
}
public ngAfterViewInit() {
if (!this._url) {
// bypass the registration
} else if (this.manual) { // register later
const sub = this._service.announcedOrder.pipe(first()).subscribe(_ => this.doRegister());
this._subscription.add(sub);
} else { // register now (default)
this.doRegister();
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment