Skip to content

Commit 52bf902

Browse files
docs(google-maps): use inject() instead of constructor injection in examples (#32836)
1 parent 43a52dd commit 52bf902

File tree

2 files changed

+14
-14
lines changed

2 files changed

+14
-14
lines changed

src/google-maps/map-directions-renderer/README.md

Lines changed: 9 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -21,28 +21,26 @@ Using the `MapDirectionsService` requires the Directions API to be enabled in Go
2121

2222
```typescript
2323
// google-maps-demo.component.ts
24-
import {Component} from '@angular/core';
24+
import {Component, inject} from '@angular/core';
2525
import {GoogleMap, MapDirectionsRenderer, MapDirectionsService} from '@angular/google-maps';
26+
import {map} from 'rxjs/operators';
2627

2728
@Component({
2829
selector: 'google-map-demo',
2930
templateUrl: 'google-map-demo.html',
30-
imports: [GoogleMap, MapDirectionsRenderer],
31+
imports: [GoogleMap, MapDirectionsRenderer],
3132
})
3233
export class GoogleMapDemo {
3334
center: google.maps.LatLngLiteral = {lat: 24, lng: 12};
3435
zoom = 4;
3536

36-
readonly directionsResults$: Observable<google.maps.DirectionsResult|undefined>;
37+
private mapDirectionsService = inject(MapDirectionsService);
3738

38-
constructor(mapDirectionsService: MapDirectionsService) {
39-
const request: google.maps.DirectionsRequest = {
40-
destination: {lat: 12, lng: 4},
41-
origin: {lat: 14, lng: 8},
42-
travelMode: google.maps.TravelMode.DRIVING
43-
};
44-
this.directionsResults$ = mapDirectionsService.route(request).pipe(map(response => response.result));
45-
}
39+
readonly directionsResults$ = this.mapDirectionsService.route({
40+
destination: {lat: 12, lng: 4},
41+
origin: {lat: 14, lng: 8},
42+
travelMode: google.maps.TravelMode.DRIVING,
43+
}).pipe(map(response => response.result));
4644
}
4745
```
4846

src/google-maps/map-geocoder/README.md

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -24,16 +24,18 @@ has billing enabled. See [here](https://developers.google.com/maps/documentation
2424

2525
```typescript
2626
// google-maps-demo.component.ts
27-
import {Component} from '@angular/core';
27+
import {Component, inject} from '@angular/core';
2828
import {MapGeocoder} from '@angular/google-maps';
2929

3030
@Component({
3131
selector: 'google-map-demo',
3232
templateUrl: 'google-map-demo.html',
3333
})
3434
export class GoogleMapDemo {
35-
constructor(geocoder: MapGeocoder) {
36-
geocoder.geocode({
35+
private geocoder = inject(MapGeocoder);
36+
37+
search() {
38+
this.geocoder.geocode({
3739
address: '1600 Amphitheatre Parkway, Mountain View, CA'
3840
}).subscribe(({results}) => {
3941
console.log(results);

0 commit comments

Comments
 (0)