1

I m playing with angular 2 for a while and now I wanted to make some fun stuff using web apis like geolocation (using navigator object) and browser Notifications.

I know how to inject window object inside of my application, but I can't find anything concerning Notification or navigator objects.

Angular2 - How to inject window into an angular2 service

Does anybody knows how can I inject them inside of a component ?

Thanks for your help

Community
  • 1
  • 1
mfrachet
  • 8,772
  • 17
  • 55
  • 110

1 Answers1

2

You cannot inject them unless you wrap it in some service, and even if you do so you will inject a service and not an API. Other than injecting you can simply use the following:

yourWindowObject.navigator.geolocation

to reach the browser geolocation or any other window property.

smnbbrv
  • 23,502
  • 9
  • 78
  • 109