From 9cc48ab2d3213db2f09a3f2df289f638771b4d51 Mon Sep 17 00:00:00 2001 From: rich Date: Fri, 11 Aug 2017 16:09:59 -0400 Subject: [PATCH] bug(ngOnDestroy): add an if statement to make sure this.subscription is defined This simply allows navigation away from a route using this package which is not currently happening every time. Closes #46 --- recaptcha/recaptcha-loader.service.ts | 2 +- recaptcha/recaptcha.component.ts | 4 +++- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/recaptcha/recaptcha-loader.service.ts b/recaptcha/recaptcha-loader.service.ts index 6ed3ebf..efe444b 100644 --- a/recaptcha/recaptcha-loader.service.ts +++ b/recaptcha/recaptcha-loader.service.ts @@ -22,7 +22,7 @@ export class RecaptchaLoaderService { /** @internal */ private language: string; - constructor( @Optional() @Inject(RECAPTCHA_LANGUAGE) language?: string) { + constructor(@Optional() @Inject(RECAPTCHA_LANGUAGE) language?: string) { this.language = language; this.init(); this.ready = RecaptchaLoaderService.ready.asObservable(); diff --git a/recaptcha/recaptcha.component.ts b/recaptcha/recaptcha.component.ts index 59322ef..f6b60eb 100644 --- a/recaptcha/recaptcha.component.ts +++ b/recaptcha/recaptcha.component.ts @@ -59,7 +59,9 @@ export class RecaptchaComponent implements AfterViewInit, OnDestroy { // reset the captcha to ensure it does not leave anything behind // after the component is no longer needed this.grecaptchaReset(); - this.subscription.unsubscribe(); + if (this.subscription) { + this.subscription.unsubscribe(); + } } /**