Error: No provider for location

See original GitHub issue

Hey there,

I followed the instructions in your README.md to install this plugin in my Angular 2 application.

I keep getting this error:

ORIGINAL EXCEPTION: No provider for Location! (Angulartics2 -> Location)

Is it because I’m using ngrx/router instead of angular2/router ?

Issue Analytics

  • State:closed
  • Created 7 years ago
  • Reactions:1
  • Comments:20 (2 by maintainers)

github_iconTop GitHub Comments

60reactions
brandonrobertscommented, Jun 29, 2016

Yes. You need

import {Location} from '@angular/common';

Add Location to your bootstrap array.

23reactions
azanebraincommented, Jul 14, 2017

For anyone else still hitting this problem but not using routes in your app, make sure to initialize the Router Module correctly and pass an empty array:

import { RouterModule } from '@angular/router'

...

@NgModule({
  declarations: [    MyComponent  ],
  imports: [
    Angulartics2Module.forRoot([ Angulartics2GoogleAnalytics ]),
    RouterModule.forRoot([])
  ],
  providers: [ ],
})
export class MyModule { }

This example is a feature module that uses forRoot. I haven’t tested it, but I bet that if your App Module is using forRoot, your “MyModule” module will probably need forChild

Read more comments on GitHub >

github_iconTop Results From Across the Web

App testing return "NullInjectorError: No provider for Location!"
I have imported Location from the wrong place so the error has appeared. ... An alternative to NullInjectorError: No provider for Location!
Read more >
NG0201: No provider for {token} found! - Angular
You see this error when you try to inject a service but have not declared a corresponding provider. A provider is a mapping...
Read more >
[Debugging] NullInjectorError: No provider for {Class}!
In this video, you'll learn what the error "NullInjectorError: No provider for {Class}!" means, how to debug it, and prevent it from ...
Read more >
NullInjectorError: No provider for Geolocation - Ionic Native
Hello,. I am receiving the following error when attempting to test with Ionic Native Geolocation as a dependency:
Read more >
How to fix angular error main.js:1 NullInjectorError
js:1 NullInjectorError: No provider for i! This error occurs in Angular when you create a singleton service and implement ...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found