Skip to content

Commit 5536972

Browse files
committed
fix(lib): support of reactive forms #99 #65
1 parent c41675e commit 5536972

File tree

9 files changed

+5721
-5123
lines changed

9 files changed

+5721
-5123
lines changed

package-lock.json

Lines changed: 5480 additions & 4981 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 33 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -34,60 +34,60 @@
3434
"private": true,
3535
"dependencies": {
3636
"@agm/core": "^1.1.0",
37-
"@angular/animations": "~9.1.7",
38-
"@angular/cdk": "^9.0.1",
39-
"@angular/common": "~9.1.7",
40-
"@angular/compiler": "~9.1.7",
41-
"@angular/core": "~9.1.7",
42-
"@angular/flex-layout": "^9.0.0-beta.29",
43-
"@angular/forms": "~9.1.7",
44-
"@angular/material": "^9.1.3",
45-
"@angular/platform-browser": "~9.1.7",
46-
"@angular/platform-browser-dynamic": "~9.1.7",
47-
"@angular/platform-server": "~9.1.7",
48-
"@angular/router": "~9.1.7",
37+
"@angular/animations": "^9.1.11",
38+
"@angular/cdk": "^9.2.4",
39+
"@angular/common": "^9.1.11",
40+
"@angular/compiler": "^9.1.11",
41+
"@angular/core": "^9.1.11",
42+
"@angular/flex-layout": "^9.0.0-beta.31",
43+
"@angular/forms": "^9.1.11",
44+
"@angular/material": "^9.2.4",
45+
"@angular/platform-browser": "^9.1.11",
46+
"@angular/platform-browser-dynamic": "^9.1.11",
47+
"@angular/platform-server": "^9.1.11",
48+
"@angular/router": "^9.1.11",
4949
"@briebug/jest-schematic": "^2.1.1",
50-
"@nguniversal/express-engine": "^9.0.2",
50+
"@nguniversal/express-engine": "^9.1.1",
5151
"angular-cli-ghpages": "^0.6.2",
5252
"angulartics2": "^8.3.0",
5353
"express": "^4.15.2",
54-
"http-server": "^0.12.1",
54+
"http-server": "^0.12.3",
5555
"ngx-markdown": "^8.2.2",
56-
"rxjs": "~6.5.4",
57-
"tslib": "^1.11.1",
56+
"rxjs": "^6.5.5",
57+
"tslib": "^1.13.0",
5858
"zone.js": "^0.10.3"
5959
},
6060
"devDependencies": {
61-
"@angular-devkit/build-angular": "~0.901.6",
62-
"@angular-devkit/build-ng-packagr": "~0.901.6",
63-
"@angular/cli": "~9.1.6",
64-
"@angular/compiler-cli": "~9.1.7",
65-
"@angular/language-service": "~9.1.7",
61+
"@angular-devkit/build-angular": "^0.901.8",
62+
"@angular-devkit/build-ng-packagr": "^0.901.8",
63+
"@angular/cli": "^9.1.8",
64+
"@angular/compiler-cli": "^9.1.11",
65+
"@angular/language-service": "^9.1.11",
6666
"@compodoc/compodoc": "^1.1.11",
67-
"@nguniversal/builders": "^9.0.2",
68-
"@release-it/conventional-changelog": "^1.1.0",
69-
"@schematics/angular": "^9.0.7",
67+
"@nguniversal/builders": "^9.1.1",
68+
"@release-it/conventional-changelog": "^1.1.4",
69+
"@schematics/angular": "^9.1.8",
7070
"@schematics/update": "^0.900.7",
71-
"@types/express": "^4.17.3",
72-
"@types/googlemaps": "^3.39.3",
73-
"@types/jasmine": "^3.5.9",
71+
"@types/express": "^4.17.6",
72+
"@types/googlemaps": "^3.39.7",
73+
"@types/jasmine": "^3.5.10",
7474
"@types/jasminewd2": "~2.0.3",
7575
"@types/jest": "25.1.2",
76-
"@types/node": "^12.12.30",
77-
"codelyzer": "^5.1.2",
76+
"@types/node": "^12.12.47",
77+
"codelyzer": "^5.2.2",
7878
"commitplease": "^3.2.0",
7979
"jasmine-core": "~3.5.0",
8080
"jasmine-spec-reporter": "~4.2.1",
8181
"jest": "25.1.0",
8282
"jest-preset-angular": "8.0.0",
83-
"ng-packagr": "^9.0.3",
84-
"protractor": "~5.4.3",
83+
"ng-packagr": "^9.1.5",
84+
"protractor": "^5.4.4",
8585
"release-it": "^12.6.3",
86-
"ts-loader": "^6.2.1",
86+
"ts-loader": "^6.2.2",
8787
"ts-node": "~8.6.2",
8888
"tslint": "~6.0.0",
8989
"typescript": "~3.7.5",
90-
"webpack-bundle-analyzer": "^3.6.1",
90+
"webpack-bundle-analyzer": "^3.8.0",
9191
"webpack-cli": "^3.3.11"
9292
},
9393
"greenkeeper": {

projects/angular-material-extensions/google-maps-autocomplete/schematics/helpers/material/ast.ts

Lines changed: 3 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,10 @@
1-
import { Tree } from '@angular-devkit/schematics';
1+
import {Tree} from '@angular-devkit/schematics';
22
import {
3-
getSourceFile as originalGetSourceFile,
4-
addModuleImportToRootModule as originalAddModuleImportToRootModule,
53
addModuleImportToModule as originalAddModuleImportToModule,
6-
typescript
4+
addModuleImportToRootModule as originalAddModuleImportToRootModule,
75
} from '@angular/cdk/schematics';
8-
import { WorkspaceProject } from '@angular-devkit/core/src/experimental/workspace';
6+
import {WorkspaceProject} from '@angular-devkit/core/src/experimental/workspace';
97

10-
/** Reads file given path and returns TypeScript source file. */
11-
export function getSourceFile(host: Tree, path: string): typescript.SourceFile {
12-
return originalGetSourceFile(host, path);
13-
}
148

159
/** Import and add module to root app module. */
1610
export function addModuleImportToRootModule(host: Tree, moduleName: string, src: string, project: WorkspaceProject) {

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

Lines changed: 37 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
import {Component, ElementRef, EventEmitter, Input, NgZone, OnInit, Output, ViewChild} from '@angular/core';
2-
import {FormControl, Validators} from '@angular/forms';
1+
import {Component, ElementRef, EventEmitter, forwardRef, Input, NgZone, OnInit, Output, ViewChild} from '@angular/core';
2+
import {ControlValueAccessor, FormControl, NG_VALUE_ACCESSOR, Validators} from '@angular/forms';
33
import {MapsAPILoader} from '@agm/core';
44
import {MatValidateAddressDirective} from '../directives/address-validator/mat-address-validator.directive';
55
import {Location} from '../interfaces/location.interface';
@@ -18,9 +18,16 @@ export enum Appearance {
1818
selector: 'mat-google-maps-autocomplete',
1919
exportAs: 'matGoogleMapsAutocomplete',
2020
templateUrl: './mat-google-maps-autocomplete.component.html',
21-
styleUrls: ['./mat-google-maps-autocomplete.component.scss']
21+
styleUrls: ['./mat-google-maps-autocomplete.component.scss'],
22+
providers: [
23+
{
24+
provide: NG_VALUE_ACCESSOR,
25+
useExisting: forwardRef(() => MatGoogleMapsAutocompleteComponent),
26+
multi: true
27+
}
28+
]
2229
})
23-
export class MatGoogleMapsAutocompleteComponent implements OnInit {
30+
export class MatGoogleMapsAutocompleteComponent implements OnInit, ControlValueAccessor {
2431

2532
@ViewChild('search')
2633
public searchElementRef: ElementRef;
@@ -74,6 +81,9 @@ export class MatGoogleMapsAutocompleteComponent implements OnInit {
7481
@Output()
7582
onLocationSelected: EventEmitter<Location> = new EventEmitter<Location>();
7683

84+
value: PlaceResult;
85+
86+
7787
private onNewPlaceResult: EventEmitter<any> = new EventEmitter();
7888
private addressValidator: MatValidateAddressDirective = new MatValidateAddressDirective();
7989

@@ -82,6 +92,9 @@ export class MatGoogleMapsAutocompleteComponent implements OnInit {
8292
this.addressValidator.validate()])
8393
);
8494

95+
propagateChange = (_: any) => {
96+
};
97+
8598
constructor(private mapsAPILoader: MapsAPILoader,
8699
private ngZone: NgZone) {
87100
}
@@ -174,6 +187,8 @@ export class MatGoogleMapsAutocompleteComponent implements OnInit {
174187
} else {
175188
// show dialog to select a address from the input
176189
// emit failed event
190+
this.value = place;
191+
this.propagateChange(this.value)
177192
}
178193
this.address = place.formatted_address;
179194
this.onAutocompleteSelected.emit(place);
@@ -199,4 +214,22 @@ export class MatGoogleMapsAutocompleteComponent implements OnInit {
199214
this.addressSearchControl.updateValueAndValidity();
200215
}
201216

217+
writeValue(obj: any): void {
218+
if (obj) {
219+
this.value = obj;
220+
}
221+
}
222+
223+
registerOnChange(fn: any): void {
224+
this.propagateChange = fn;
225+
}
226+
227+
registerOnTouched(fn: any): void {
228+
throw new Error('Method not implemented.');
229+
}
230+
231+
setDisabledState?(isDisabled: boolean): void {
232+
throw new Error('Method not implemented.');
233+
}
234+
202235
}

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

Lines changed: 31 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
import {Component, EventEmitter, Input, OnInit, Output} from '@angular/core';
2-
import {FormBuilder, FormGroup, Validators} from '@angular/forms';
1+
import {Component, EventEmitter, forwardRef, Input, OnInit, Output} from '@angular/core';
2+
import {ControlValueAccessor, FormBuilder, FormGroup, NG_VALUE_ACCESSOR, Validators} from '@angular/forms';
33

44
import {parseGermanAddress} from '../../helpers/parser';
55
import {GermanAddress} from '../../interfaces';
@@ -10,9 +10,16 @@ import {InputAnimations} from '../../animations';
1010
selector: 'mat-search-google-maps-autocomplete',
1111
templateUrl: './mat-search-google-maps-autocomplete.component.html',
1212
styleUrls: ['./mat-search-google-maps-autocomplete.component.scss'],
13-
animations: InputAnimations
13+
animations: InputAnimations,
14+
providers: [
15+
{
16+
provide: NG_VALUE_ACCESSOR,
17+
useExisting: forwardRef(() => MatSearchGoogleMapsAutocompleteComponent),
18+
multi: true
19+
}
20+
]
1421
})
15-
export class MatSearchGoogleMapsAutocompleteComponent implements OnInit {
22+
export class MatSearchGoogleMapsAutocompleteComponent implements OnInit, ControlValueAccessor {
1623

1724
@Input()
1825
appearance: string | Appearance = Appearance.STANDARD;
@@ -69,6 +76,8 @@ export class MatSearchGoogleMapsAutocompleteComponent implements OnInit {
6976
germanAddress: GermanAddress;
7077
addressFormGroup: FormGroup;
7178

79+
propagateChange = (_: any) => {
80+
};
7281

7382
constructor(private formBuilder: FormBuilder) {
7483
}
@@ -111,7 +120,25 @@ export class MatSearchGoogleMapsAutocompleteComponent implements OnInit {
111120
this.addressFormGroup.get('locality.long').patchValue(germanAddress.locality.long);
112121
}
113122

123+
this.value = germanAddress;
124+
this.propagateChange(this.value);
114125
this.onGermanAddressMapped.emit(germanAddress);
115126
}
116127

128+
writeValue(obj: any): void {
129+
if (obj) {
130+
this.value = obj;
131+
}
132+
}
133+
134+
registerOnChange(fn: any): void {
135+
this.propagateChange = fn;
136+
}
137+
138+
registerOnTouched(fn: any): void {
139+
}
140+
141+
setDisabledState(isDisabled: boolean): void {
142+
}
143+
117144
}

projects/angular-material-extensions/google-maps-autocomplete/src/lib/directives/mat-google-maps-autocomplete.directive.ts

Lines changed: 33 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
import {Directive, ElementRef, EventEmitter, Inject, Input, NgZone, OnInit, Output, PLATFORM_ID} from '@angular/core';
2-
import {FormControl, Validators} from '@angular/forms';
1+
import {Directive, ElementRef, EventEmitter, forwardRef, Inject, Input, NgZone, OnInit, Output, PLATFORM_ID} from '@angular/core';
2+
import {ControlValueAccessor, FormControl, NG_VALUE_ACCESSOR, Validators} from '@angular/forms';
33
import {MatValidateAddressDirective} from '../directives/address-validator/mat-address-validator.directive';
44
import {MapsAPILoader} from '@agm/core';
55
import {Location} from '../interfaces/location.interface';
@@ -11,8 +11,15 @@ import AutocompleteOptions = google.maps.places.AutocompleteOptions;
1111
@Directive({
1212
selector: '[matGoogleMapsAutocomplete]',
1313
exportAs: 'matGoogleMapsAutocomplete',
14+
providers: [
15+
{
16+
provide: NG_VALUE_ACCESSOR,
17+
useExisting: forwardRef(() => MatGoogleMapsAutocompleteDirective),
18+
multi: true
19+
}
20+
]
1421
})
15-
export class MatGoogleMapsAutocompleteDirective implements OnInit {
22+
export class MatGoogleMapsAutocompleteDirective implements OnInit, ControlValueAccessor {
1623

1724
@Input()
1825
address: PlaceResult | string;
@@ -47,6 +54,8 @@ export class MatGoogleMapsAutocompleteDirective implements OnInit {
4754
@Output()
4855
onLocationSelected: EventEmitter<Location> = new EventEmitter<Location>();
4956

57+
value: PlaceResult;
58+
5059
private onNewPlaceResult: EventEmitter<any> = new EventEmitter();
5160
private addressValidator: MatValidateAddressDirective = new MatValidateAddressDirective();
5261

@@ -55,6 +64,9 @@ export class MatGoogleMapsAutocompleteDirective implements OnInit {
5564
this.addressValidator.validate()])
5665
);
5766

67+
propagateChange = (_: any) => {
68+
};
69+
5870
constructor(@Inject(PLATFORM_ID) public platformId: string,
5971
public elemRef: ElementRef,
6072
public mapsAPILoader: MapsAPILoader,
@@ -151,6 +163,8 @@ export class MatGoogleMapsAutocompleteDirective implements OnInit {
151163
} else {
152164
// show dialog to select a address from the input
153165
// emit failed event
166+
this.value = place;
167+
this.propagateChange(this.value)
154168
}
155169
this.address = place.formatted_address;
156170
this.onAutocompleteSelected.emit(place);
@@ -165,4 +179,20 @@ export class MatGoogleMapsAutocompleteDirective implements OnInit {
165179
.catch((err) => console.log(err));
166180
}
167181

182+
registerOnChange(fn: any): void {
183+
this.propagateChange = fn;
184+
}
185+
186+
registerOnTouched(fn: any): void {
187+
}
188+
189+
setDisabledState(isDisabled: boolean): void {
190+
}
191+
192+
writeValue(obj: any): void {
193+
if (obj) {
194+
this.value = obj;
195+
}
196+
}
197+
168198
}

0 commit comments

Comments
 (0)