@@ -11,7 +11,7 @@ export class BindQueryParamsManager<T = any> {
11
11
private defs : QueryParamDef < T > [ ] ;
12
12
private group : FormGroup ;
13
13
private $destroy = new Subject ( ) ;
14
- private defsSynced = false ;
14
+ private defsSynced : Record < keyof T , boolean > = { } as Record < keyof T , boolean > ;
15
15
16
16
connect ( group : FormGroup ) {
17
17
this . group = group ;
@@ -28,7 +28,7 @@ export class BindQueryParamsManager<T = any> {
28
28
}
29
29
30
30
onInit ( ) {
31
- this . updateControl ( this . defs , ( def ) => def . strategy === 'twoWay' ) ;
31
+ this . updateControl ( this . defs , { emitEvent : true } , ( def ) => def . strategy === 'twoWay' ) ;
32
32
33
33
const controls = this . defs . map ( ( def ) => {
34
34
return this . group . get ( def . path ) . valueChanges . pipe (
@@ -79,11 +79,21 @@ export class BindQueryParamsManager<T = any> {
79
79
return result ;
80
80
}
81
81
82
- syncDefs ( queryKeys : ( keyof T & string ) | ( keyof T & string ) [ ] ) {
83
- if ( ! this . defsSynced ) {
84
- const defs = coerceArray ( queryKeys ) . map ( ( key ) => this . getDef ( key as keyof T ) ) ;
85
- this . updateControl ( defs ) ;
86
- this . defsSynced = true ;
82
+ syncDefs (
83
+ queryKeys : ( keyof T & string ) | ( keyof T & string ) [ ] ,
84
+ options : { emitEvent : boolean } = { emitEvent : true }
85
+ ) {
86
+ const defs = [ ] ;
87
+
88
+ coerceArray ( queryKeys ) . forEach ( ( key ) => {
89
+ if ( ! this . defsSynced [ key ] ) {
90
+ this . defsSynced [ key ] = true ;
91
+ defs . push ( this . getDef ( key as keyof T ) ) ;
92
+ }
93
+ } ) ;
94
+
95
+ if ( defs . length ) {
96
+ this . updateControl ( defs , options ) ;
87
97
}
88
98
}
89
99
@@ -95,7 +105,11 @@ export class BindQueryParamsManager<T = any> {
95
105
} ) ;
96
106
}
97
107
98
- private updateControl ( defs : QueryParamDef [ ] , updatePredicate = ( def : QueryParamDef ) => true ) {
108
+ private updateControl (
109
+ defs : QueryParamDef [ ] ,
110
+ options : { emitEvent : boolean } ,
111
+ updatePredicate = ( def : QueryParamDef ) => true
112
+ ) {
99
113
const queryParams = new URLSearchParams ( this . options . windowRef . location . search ) ;
100
114
let value = { } ;
101
115
@@ -110,7 +124,7 @@ export class BindQueryParamsManager<T = any> {
110
124
}
111
125
112
126
if ( Object . keys ( value ) . length ) {
113
- this . group . patchValue ( value ) ;
127
+ this . group . patchValue ( value , options ) ;
114
128
}
115
129
}
116
130
}
0 commit comments