Skip to content

docs-bug(@angular/google-maps): missing documentation #24978

@dsl400

Description

@dsl400

Documentation Feedback

The documentation page on angular.io is missing and I could not find any article that explains how to use @angular/google-maps in a sub module with lazy-load.

The map loads but when I try to add markers I get this errors

ERROR NullInjectorError: R3InjectorError(AppModule)[GoogleMap -> GoogleMap -> GoogleMap]: 
  NullInjectorError: No provider for GoogleMap!

If I add GoogleMap to providers in MapModule the error is now

ERROR Error: Cannot access Google Map information before the API has been initialized. Please wait for the API to load before trying to interact with it.

MapModule

@NgModule({
          declarations: [
            MyMapComponent
          ],
          imports: [
            CommonModule,
            GoogleMapsModule, 
            HttpClientJsonpModule
          ],
          exports:[
            MyMapComponent
          ],
          providers:[
            GoogleMap //<<<<<<<< is this ok ?
          ]
        })

MyMapComponent

  @Component({
      selector: 'my-map',
      templateUrl: './my-map.component.html',
      styleUrls: ['./my-map.component.scss']
    })
    export class MyMapComponent implements OnInit {
    
    
      apiLoaded: Observable<boolean>;
      mapOptions: google.maps.MapOptions = {
        center: { lat: 45.8, lng: 24.5 },
        zoom: 7,
        disableDoubleClickZoom: true,
        disableDefaultUI: true,
      }
    
      markerPositions:any = []
      // map!: google.maps.Map
    
      @ViewChild(GoogleMap)
      public map!: GoogleMap;
    
    
      constructor(
        httpClient: HttpClient,
      ) {
        this.apiLoaded = httpClient.jsonp(`https://maps.googleapis.com/maps/api/js?key=${environment.mapsApiKey}`, 'callback')
          .pipe(
            map(() => true),
            catchError((err) => of(false)),
          );
      }
    
      ngOnInit(): void { }
    
      onMapClick(event: any) {
        console.log(event)
      }

      onMapReady(map: any) {
        map.addListener(this.onMapClick)
      }
    
    }

my-map.controller.html


    <div *ngIf="apiLoaded | async" fxFill >
        <google-map (mapInitialized)="onMapReady($event)" [options]="mapOptions" (mapClick)="addMarker($event)" ></google-map>
        <map-marker [position]="{lat:45.8,lng:24.5}"></map-marker>
    </div>

Affected documentation page

https://material.angular.io/components/google-maps/overview

Activity

added
docsThis issue is related to documentation
needs triageThis issue needs to be triaged by the team
on May 26, 2022
added
P3An issue that is relevant to core functions, but does not impede progress. Important, but not urgent
and removed
needs triageThis issue needs to be triaged by the team
on Jun 10, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    P3An issue that is relevant to core functions, but does not impede progress. Important, but not urgentarea: google-mapsdocsThis issue is related to documentation

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

      Development

      No branches or pull requests

        Participants

        @dsl400@zarend

        Issue actions

          docs-bug(@angular/google-maps): missing documentation · Issue #24978 · angular/components