Skip to content

Commit b70262e

Browse files
committed
fix(core): remove parameter's parent upon remove
fixes #120 Signed-off-by: Ingo Bürk <ingo.buerk@tngtech.com>
1 parent ba1403d commit b70262e

3 files changed

Lines changed: 4 additions & 2 deletions

File tree

projects/ngqp/core/src/lib/model/query-param-group.spec.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -230,6 +230,7 @@ describe(QueryParamGroup.name, () => {
230230
it('can remove an existing parameter from a group', () => {
231231
group.remove('q');
232232
expect(group.get('q')).toBeNull();
233+
expect((stringParam as any).parent).toBe(null);
233234
});
234235

235236
it('throws if the parameter does not exist', () => {

projects/ngqp/core/src/lib/model/query-param-group.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -115,6 +115,7 @@ export class QueryParamGroup {
115115
}
116116

117117
delete this.queryParams[ queryParamName ];
118+
queryParam._setParent(null);
118119
queryParam._clearChangeFunctions();
119120
}
120121

projects/ngqp/core/src/lib/model/query-param.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ abstract class AbstractQueryParamBase<T> {
99

1010
public abstract value: T;
1111

12-
protected parent: QueryParamGroup;
12+
protected parent: QueryParamGroup | null = null;
1313
protected _valueChanges = new Subject<T>();
1414
protected changeFunctions: OnChangeFunction<T>[] = [];
1515

@@ -35,7 +35,7 @@ abstract class AbstractQueryParamBase<T> {
3535
}): void;
3636

3737
public _setParent(parent: QueryParamGroup): void {
38-
if (this.parent) {
38+
if (this.parent && parent) {
3939
throw new Error(`Parameter already belongs to a QueryParamGroup.`);
4040
}
4141

0 commit comments

Comments
 (0)