Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

GoogleMapsAPIWrapper is required to be passed as a provider #1036

Closed
maneesht opened this issue Jun 7, 2017 · 3 comments
Closed

GoogleMapsAPIWrapper is required to be passed as a provider #1036

maneesht opened this issue Jun 7, 2017 · 3 comments

Comments

@maneesht
Copy link

maneesht commented Jun 7, 2017

Issue description
When I try injecting GoogleMapsAPIWrapper into one of my components, I have to provide the Wrapper either to my NgModule or my NgComponent. This doesn't seem like expected behavior.
If this is an Angular 4 service, you should be able to just import AgmCoreModule and not have to use the providers array in your module.

Steps to reproduce and a minimal demo of the problem

@Component({
  selector: 'app-root',
  templateUrl: './app.component.html',
  styleUrls: ['./app.component.css']
})
constructor(googleMapsAPIWrapper: GoogleMapsAPIWrapper) { //

}
@NgModule({
  declarations: [
    AppComponent
  ],
  imports: [
    BrowserModule,
    FormsModule,
    AgmCoreModule.forRoot()
  ],
  providers: [  ], //wrong
  bootstrap: [AppComponent]
})
export class AppModule { }

The above gives an error.
You need to change to
providers: [ GoogleMapsAPIWrapper ], bootstrap: [AppComponent]

Expected/desired behavior
You shouldn't have to provide GoogleMapsAPIWrapper to your Module.

angular2 & angular-google-maps version
angular: 4.1.3

agm/core: 1.0.0-beta.0

Other information

@sebholstein
Copy link
Owner

The GoogleMapsAPIWraper gets created when a agm-map instance gets created. This is fully intentional. We maintain one instance per map. If you want to get the instance of the map, you can create a custom component and inject the GoogleMapsAPIWrapper via the constructor. So I'm closing this.

@Chris-Devine
Copy link

@SebastianM Do you have an example of what your saying as i would like to try this out?

@akhilshastri
Copy link

@SebastianM seems it not working.. else i am missing something.. can you please help,

The promise is not getting resolved, line no 25 is not getting executed in app.component.ts in below repo. ( there is no error in console)

https://stackblitz.com/edit/agm-google-maps-api-wrapper-not-working

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants