Skip to content

Commit 4fdcfe1

Browse files
committed
fix(core): Fix deserialization on non-multi controls
For non-multi controls, we need to make sure the deserializer is invoked if the param is absent.
1 parent c4787a4 commit 4fdcfe1

1 file changed

Lines changed: 9 additions & 4 deletions

File tree

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

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,9 @@ export class QueryParamGroupDirective implements OnInit, OnDestroy {
7272
this.routerAdapter.queryParamMap.subscribe(queryParamMap => {
7373
Object.keys(this.queryParamGroup.controls).forEach(controlName => {
7474
const control: QueryParamControl<any> = this.queryParamGroup.get(controlName);
75-
const newModel = this.deserialize(control, queryParamMap.getAll(control.name));
75+
const newModel = this.deserialize(control,
76+
control.multi ? queryParamMap.getAll(control.name) : queryParamMap.get(control.name)
77+
);
7678

7779
// Get the directive, if it has been initialized yet.
7880
const directive = this.directives.find(dir => dir.name === controlName);
@@ -157,9 +159,12 @@ export class QueryParamGroupDirective implements OnInit, OnDestroy {
157159
: [control.serialize(model)];
158160
}
159161

160-
private deserialize<T = any>(control: QueryParamControl<T>, values: string[]): Unpack<T> | Unpack<T>[] {
161-
const deserialized: Unpack<T>[] = values.map(control.deserialize);
162-
return isMultiControl(control) ? deserialized : deserialized[0];
162+
private deserialize<T = any>(control: QueryParamControl<T>, values: string | string[]): Unpack<T> | Unpack<T>[] {
163+
if (Array.isArray(values)) {
164+
return values.map(control.deserialize);
165+
} else {
166+
return control.deserialize(values);
167+
}
163168
}
164169

165170
private get routerOptions(): RouterAdapterOptions {

0 commit comments

Comments
 (0)