Skip to content

Commit 6bd7196

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

File tree

4 files changed

+51
-7
lines changed

4 files changed

+51
-7
lines changed

LICENSE

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
The MIT License (MIT)
22

3-
Copyright (c) 2020 Anthony Nahas
3+
Copyright (c) 2019-2020 Anthony Nahas
44

55
Permission is hereby granted, free of charge, to any person obtaining
66
a copy of this software and associated documentation files (the

README.md

Lines changed: 46 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,7 @@ View all the directives and components in action at [https://angular-material-ex
6666
* [Angular](https://angular.io) (*requires* Angular 2 or higher | we are using already V9 ;)
6767

6868
for the directive as standalone you just need to install the agm core module
69-
- [agm - angular google maps v1.0.0](https://www.npmjs.com/package/@agm/core)
69+
- [agm - angular google maps v1.1.0](https://www.npmjs.com/package/@agm/core)
7070

7171
```bash
7272
npm i @agm/core
@@ -108,6 +108,7 @@ for the ui input component, please consider to install the following packages
108108
- [angular forms v9.x](https://www.npmjs.com/package/@angular/forms)
109109
- [angular material v9.x](https://www.npmjs.com/package/@angular/material)
110110
- [angular cdk v9.x](https://www.npmjs.com/package/@angular/cdk)
111+
- [agm - angular google maps v1.1.0](https://www.npmjs.com/package/@agm/core)
111112

112113
```bash
113114
npm i @angular/cdk @angular/material @angular/animations @angular/forms
@@ -302,13 +303,55 @@ export class HomeComponent implements OnInit {
302303

303304
```
304305

306+
307+
#### Reactive Forms Example
308+
309+
```html
310+
<form [formGroup]="addressFormGroup">
311+
<mat-search-google-maps-autocomplete formControlName="address">
312+
</mat-search-google-maps-autocomplete>
313+
314+
// OR
315+
316+
<mat-google-maps-autocomplete formControlName="address">
317+
</mat-google-maps-autocomplete>
318+
319+
</form>
320+
```
321+
322+
```typescript
323+
324+
import {Component, OnInit} from '@angular/core';
325+
import {FormControl, FormGroup} from '@angular/forms';
326+
327+
@Component({
328+
selector: 'app-root',
329+
templateUrl: './app.component.html',
330+
styleUrls: ['./app.component.scss']
331+
})
332+
export class AppComponent implements OnInit {
333+
334+
addressFormGroup: FormGroup;
335+
336+
ngOnInit(): void {
337+
this.addressFormGroup = new FormGroup({
338+
address: new FormControl(),
339+
});
340+
341+
this.addressFormGroup.get('address').valueChanges.subscribe(value => console.log('value changed', value))
342+
}
343+
}
344+
345+
```
346+
305347
<a name="api"/>
306348

307349
### API - for more info please visit the official documentation [Maps JavaScript API](https://developers.google.com/maps/documentation/javascript/places-autocomplete?hl=en)
308350

309351
### `matGoogleMapsAutocomplete`
310352
| option | bind | type | default | description |
311353
|:-------------------|:--------:|:------:|:------------:|:-------------------------------------------------------------------------------------------------|
354+
| value | `Input()` | PlaceResult ; | - |
312355
| address | `Input()` | PlaceResult | string; | - |
313356
| country | `Input()` | string | string[]; | - | can be used to restrict results to specific groups. Currently, you can use componentRestrictions to filter by up to 5 countries. Countries must be passed as as a two-character, ISO 3166-1 Alpha-2 compatible country code. Multiple countries must be passed as a list of country codes.
314357
| placeIdOnly | `Input()` | boolean | - | can be used to instruct the Autocomplete widget to retrieve only Place IDs. On calling getPlace() on the Autocomplete object, the PlaceResult made available will only have the place id, types and name properties set. You can use the returned place ID with calls to the Places, Geocoding, Directions or Distance Matrix services.
@@ -318,8 +361,8 @@ export class HomeComponent implements OnInit {
318361
| autoCompleteOptions | `Input()` | AutocompleteOptions | - | all above inputs in one object! The passed data to this object will be merged with the input if they exists
319362
| onChange | `Output()` | PlaceResult | string | null | - | event when the input form value changed
320363
| onAutocompleteSelected | `Output()` | PlaceResult | - | the event will be fired when a place has been selected via the google maps autocomplete component
364+
| onGermanAddressMapped | `Output()` | GermanAddress | - | the event will be fired when a place has been selected and mapped to the german address interface |
321365
| onLocationSelected | `Output()` | Location | - | the event will be fired when a place has been selected via the google maps autocomplete component |
322-
| onLocationSelected | `Output()` | GermanAddress | - | the event will be fired when a place has been selected and mapped to the german address interface |
323366

324367
#### Supported Types
325368

@@ -463,5 +506,5 @@ $ cd demo && npm i && npm start
463506

464507
## License
465508

466-
Copyright (c) 2019 [Anthony Nahas](https://github.com/AnthonyNahas). Licensed under the MIT License (MIT)
509+
Copyright (c) 2019-2020 [Anthony Nahas](https://github.com/AnthonyNahas). Licensed under the MIT License (MIT)
467510

projects/angular-material-extensions/google-maps-autocomplete/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@
5151
"@angular/common": "^9.0.0",
5252
"@angular/core": "^9.0.0",
5353
"@angular/platform-browser": "^9.0.0",
54-
"@angular/flex-layout": "^9.0.0-beta.29",
54+
"@angular/flex-layout": "^9.0.0-beta.31",
5555
"@angular/forms": "^9.0.0",
5656
"@angular/cdk": "^9.0.0",
5757
"@angular/material": "^9.0.0",

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

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,9 @@ export class MatGoogleMapsAutocompleteComponent implements OnInit, ControlValueA
4747
@Input()
4848
appearance: string | Appearance = Appearance.STANDARD;
4949

50+
@Input()
51+
value: PlaceResult;
52+
5053
@Input()
5154
address: PlaceResult | string;
5255

@@ -81,8 +84,6 @@ export class MatGoogleMapsAutocompleteComponent implements OnInit, ControlValueA
8184
@Output()
8285
onLocationSelected: EventEmitter<Location> = new EventEmitter<Location>();
8386

84-
value: PlaceResult;
85-
8687

8788
private onNewPlaceResult: EventEmitter<any> = new EventEmitter();
8889
private addressValidator: MatValidateAddressDirective = new MatValidateAddressDirective();

0 commit comments

Comments
 (0)