Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

NullInjectorError: No provider for ActivatedRoute

when I execute my angular application locally, this error occurred suddenly even without doing any code changes while the same code base can be run in a separate machine with the same configuration.

  • node version:v16.17.0

ERROR Error: Uncaught (in promise): NullInjectorError: R3InjectorError(AppModule)[ActivatedRoute -> ActivatedRoute -> ActivatedRoute]: NullInjectorError: No provider for ActivatedRoute!

enter image description here

like image 216
Pubudu Mahesh Meththananda Avatar asked Sep 03 '25 14:09

Pubudu Mahesh Meththananda


1 Answers

Try to add the following import in AppModule file

imports: [ 
    RouterModule.forRoot([]),
    ...
  ],

To import RouterModule you should do something like this:

import { RouterModule } from '@angular/router';
like image 132
Benny Avatar answered Sep 05 '25 02:09

Benny



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!