Angular NullInjectorError No provider for Location

Error: NullInjectorError: No provider for Location!

NullInjectorError: R3InjectorError(AppModule)[Service -> Location -> Location -> Location]: 
  NullInjectorError: No provider for Location!
    at NullInjector.get (core.mjs:6364:27)
    at R3Injector.get (core.mjs:6791:33)
    at R3Injector.get (core.mjs:6791:33)
    at R3Injector.get (core.mjs:6791:33)
    at injectInjectorOnly (core.mjs:4775:33)
    at ɵɵinject (core.mjs:4779:12)

Solution:

Add the following import at the top of the file and the issue will be fixed:

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