Hotfix clearing of extensions on navigation

This commit is contained in:
Sean Engelhardt 2019-07-08 11:34:14 +02:00
parent 46f39f96e8
commit 5817c45e01

View File

@ -1,13 +1,14 @@
import { Component, OnInit, Input, Output, EventEmitter } from '@angular/core'; import { Component, OnInit, Input, Output, EventEmitter, OnDestroy } from '@angular/core';
import { BehaviorSubject } from 'rxjs'; import { BehaviorSubject, Subscription } from 'rxjs';
import { FormGroup, FormBuilder } from '@angular/forms'; import { FormGroup, FormBuilder } from '@angular/forms';
import { Router, NavigationEnd } from '@angular/router';
@Component({ @Component({
selector: 'os-extension-field', selector: 'os-extension-field',
templateUrl: './extension-field.component.html', templateUrl: './extension-field.component.html',
styleUrls: ['./extension-field.component.scss'] styleUrls: ['./extension-field.component.scss']
}) })
export class ExtensionFieldComponent implements OnInit { export class ExtensionFieldComponent implements OnInit, OnDestroy {
/** /**
* Optional additional classes for the `mat-chip`. * Optional additional classes for the `mat-chip`.
*/ */
@ -113,18 +114,31 @@ export class ExtensionFieldComponent implements OnInit {
*/ */
public editMode = false; public editMode = false;
/**
* Hold the nav subscription
*/
private navigationSubscription: Subscription;
/** /**
* Constructor * Constructor
* *
* @param fb The FormBuilder * @param fb The FormBuilder
*/ */
public constructor(private fb: FormBuilder) {} public constructor(private fb: FormBuilder, private router: Router) {}
/** /**
* OnInit-method. * OnInit-method.
*/ */
public ngOnInit(): void { public ngOnInit(): void {
this.navigationSubscription = this.router.events.subscribe(navEvent => {
if (navEvent instanceof NavigationEnd) {
this.editMode = false;
this.extensionFieldForm.reset();
}
});
this.initInput(); this.initInput();
this.extensionFieldForm = this.fb.group({ this.extensionFieldForm = this.fb.group({
list: this.searchList ? [[]] : undefined list: this.searchList ? [[]] : undefined
}); });
@ -133,7 +147,7 @@ export class ExtensionFieldComponent implements OnInit {
if (this.listSubmitOnChange) { if (this.listSubmitOnChange) {
this.listChange.emit(value); this.listChange.emit(value);
} }
if (this.appendValueToInput) { if (this.appendValueToInput && this.inputControl.length) {
this.inputControl = this.inputControl.concat( this.inputControl = this.inputControl.concat(
`[${this.listValuePrefix}${value}${this.listValueSuffix}]` `[${this.listValuePrefix}${value}${this.listValueSuffix}]`
); );
@ -141,6 +155,13 @@ export class ExtensionFieldComponent implements OnInit {
}); });
} }
/**
* On destroy unsubscribe from the nav subscription
*/
public ngOnDestroy(): void {
this.navigationSubscription.unsubscribe();
}
/** /**
* Function to switch to or from editing-mode. * Function to switch to or from editing-mode.
* *