From e32b01edc96fd2a43fd5a3c3729529499066b53a Mon Sep 17 00:00:00 2001 From: Kyle Spearrin Date: Sat, 24 Feb 2018 15:19:16 -0500 Subject: [PATCH] input event, not change --- .../vault/password-generator.component.html | 6 ++--- src/app/vault/password-generator.component.ts | 22 +++++++++++++++---- 2 files changed, 21 insertions(+), 7 deletions(-) diff --git a/src/app/vault/password-generator.component.html b/src/app/vault/password-generator.component.html index 2bb6c4ebe4..6fc1b3e6f3 100644 --- a/src/app/vault/password-generator.component.html +++ b/src/app/vault/password-generator.component.html @@ -27,7 +27,7 @@
+ (input)="saveOptions()">
@@ -57,12 +57,12 @@
-
-
diff --git a/src/app/vault/password-generator.component.ts b/src/app/vault/password-generator.component.ts index 265bc00646..36fa12353e 100644 --- a/src/app/vault/password-generator.component.ts +++ b/src/app/vault/password-generator.component.ts @@ -4,8 +4,10 @@ import { ToasterService } from 'angular2-toaster'; import { Angulartics2 } from 'angulartics2'; import { + ChangeDetectorRef, Component, EventEmitter, + NgZone, Input, OnInit, Output, @@ -30,7 +32,8 @@ export class PasswordGeneratorComponent implements OnInit { constructor(private passwordGenerationService: PasswordGenerationService, private analytics: Angulartics2, private platformUtilsService: PlatformUtilsService, private i18nService: I18nService, - private toasterService: ToasterService) { } + private toasterService: ToasterService, private ngZone: NgZone, + private changeDetectorRef: ChangeDetectorRef) { } async ngOnInit() { this.options = await this.passwordGenerationService.getOptions(); @@ -44,15 +47,19 @@ export class PasswordGeneratorComponent implements OnInit { // Save password once the slider stop moving. slider.addEventListener('change', async (e) => { e.preventDefault(); - this.saveOptions(false); + this.functionWithChangeDetection(() => { + this.saveOptions(false); + }); await this.passwordGenerationService.addHistory(this.password); this.analytics.eventTrack.next({ action: 'Regenerated Password' }); }); // Regenerate while slider moving slider.addEventListener('input', (e) => { e.preventDefault(); - this.normalizeOptions(); - this.password = this.passwordGenerationService.generatePassword(this.options); + this.functionWithChangeDetection(() => { + this.normalizeOptions(); + this.password = this.passwordGenerationService.generatePassword(this.options); + }); }); } } @@ -126,4 +133,11 @@ export class PasswordGeneratorComponent implements OnInit { this.options.minSpecial = this.options.length - this.options.minNumber; } } + + private functionWithChangeDetection(func: Function) { + this.ngZone.run(async () => { + func(); + this.changeDetectorRef.detectChanges(); + }); + } }