Last active
November 2, 2018 22:12
-
-
Save bob-lee/6a4b3373e9b174947b0ccf1b8aaf446b to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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