Skip to content

Commit 829a3f4

Browse files
committed
fix(lib): improved the reactive forms mechanism
1 parent a6c8e8e commit 829a3f4

File tree

1 file changed

+12
-6
lines changed

1 file changed

+12
-6
lines changed

projects/angular-material-extensions/google-maps-autocomplete/src/lib/component/mat-search-google-maps-autocomplete/mat-search-google-maps-autocomplete.component.ts

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -102,6 +102,7 @@ export class MatSearchGoogleMapsAutocompleteComponent implements OnInit, Control
102102
set value(value: GermanAddress) {
103103
this._value = value;
104104
this.propagateChange(this.value);
105+
console.log('setValue', this._value);
105106
}
106107

107108
ngOnInit() {
@@ -128,50 +129,55 @@ export class MatSearchGoogleMapsAutocompleteComponent implements OnInit, Control
128129
.pipe(distinctUntilChanged(), debounceTime(400), takeUntil(this._unsubscribeAll))
129130
.subscribe(streetName => {
130131
console.log('custom input for street Name', streetName);
131-
console.log('custom input - new german address', this.value);
132+
console.log('custom input - new german address streetName', this.value);
132133
!this.value ? this.value = {streetName} : this.value.streetName = streetName;
133134
this.value.displayAddress = this.parseDisplayAddress();
135+
this.propagateChange(this.value);
134136
});
135137
this.addressFormGroup
136138
.get('streetNumber')
137139
.valueChanges
138140
.pipe(distinctUntilChanged(), debounceTime(400), takeUntil(this._unsubscribeAll))
139141
.subscribe(streetNumber => {
140142
!this.value ? this.value = {streetNumber} : this.value.streetNumber = streetNumber;
141-
console.log('custom input - new german address', this.value);
143+
console.log('custom input - new german address streetNumber', this.value);
142144
this.value.displayAddress = this.parseDisplayAddress();
145+
this.propagateChange(this.value);
143146
});
144147
this.addressFormGroup
145148
.get('postalCode')
146149
.valueChanges
147150
.pipe(distinctUntilChanged(), debounceTime(400), takeUntil(this._unsubscribeAll))
148151
.subscribe(postalCode => {
149152
!this.value ? this.value = {postalCode} : this.value.postalCode = postalCode;
150-
console.log('custom input - new german address', this.value);
153+
console.log('custom input - new german address postalCode', this.value);
151154
this.value.displayAddress = this.parseDisplayAddress();
155+
this.propagateChange(this.value);
152156
});
153157
this.addressFormGroup
154158
.get('vicinity')
155159
.valueChanges
156160
.pipe(distinctUntilChanged(), debounceTime(400), takeUntil(this._unsubscribeAll))
157161
.subscribe(vicinity => {
158162
!this.value ? this.value = {vicinity} : this.value.vicinity = vicinity;
159-
console.log('custom input - new german address', this.value);
163+
console.log('custom input - new german address vicinity', this.value);
160164
this.value.displayAddress = this.parseDisplayAddress();
165+
this.propagateChange(this.value);
161166
});
162167
this.addressFormGroup
163168
.get('locality')
164169
.valueChanges
165170
.pipe(distinctUntilChanged(), debounceTime(400), takeUntil(this._unsubscribeAll))
166171
.subscribe(locality => {
167172
!this.value ? this.value = {locality} : this.value.locality = locality;
168-
console.log('custom input - new german address', this.value);
173+
console.log('custom input - new german address locality', this.value);
169174
this.value.displayAddress = this.parseDisplayAddress();
175+
this.propagateChange(this.value);
170176
});
171177
}
172178

173179
parseDisplayAddress() {
174-
return `${this.value?.streetName} ${this.value?.streetNumber}, ${this.value?.postalCode} ${this.value?.locality?.long}`
180+
return `${this.value?.streetName ? this.value?.streetName : ''} ${this.value?.streetNumber ? this.value?.streetNumber : ''}${this.value?.postalCode || this.value?.locality?.long ? ', ' : ''}${this.value?.postalCode ? this.value?.postalCode : ''} ${this.value?.locality?.long ? this.value?.locality?.long : ''}`
175181
}
176182

177183
syncAutoComplete($event: google.maps.places.PlaceResult) {

0 commit comments

Comments
 (0)