add a getter for the map wrapper in the map directive#311
Conversation
|
There were the following issues with your Pull Request
Contribution guidelines are available at https://github.com/SebastianM/angular2-google-maps/blob/master/CONTRIBUTING.md This message was auto-generated by https://gitcop.com |
|
@SebastianM Test fails seem to be because of unrelated tslint errors, fixing those too. |
| }); | ||
| } | ||
|
|
||
| get wrapper(): GoogleMapsAPIWrapper { return this._mapsWrapper; } |
There was a problem hiding this comment.
@SebastianM This is the only real change in this PR
There was a problem hiding this comment.
@alexweber I don't understand the need for this. You can already get the GoogleMapsAPIWrapper when you create a custom component and inject it in the constructor.
There was a problem hiding this comment.
@SebastianM Yes, but it's not the same instance of the GoogleMapsAPIWrapper as the one used by the map. If you call getMap or anything else on it it fails. This is because the provider is specified in the map component....
There was a problem hiding this comment.
Yeah, you have to place your custom component inside the compontent. This is a conscious design decision.
|
@SebastianM Ah, thanks! I finally get it now... I can just create any directive, place it inside the map and inject the wrapper to get access to it. I see now how this promotes a cleaner way to interact with the map, good job! 👍 |
|
@alexweber can you share the code? |
|
your code may looks like following
and then in appGmap directive: `export class GmapDirective implements OnInit { constructor(private mapWrapper: GoogleMapsAPIWrapper) { } ngOnInit() { |
Allow the GoogleMapsAPIWrapper instance used in the directive to be retrieved.
Since the provider is overridden per map instance, I haven't found a way to access the same GoogleMapsAPIWrapper instance as injecting it into my component gives me a new instance, even if provided at the app bootstrap level.
I get that with multiple maps on the page we really don't want only a single api wrapper to be available, hence the provider on the directive level, however, it would be incredibly useful to gain access to that api wrapper instance in order to call
getMap()on it and so on.