The class ‘…Service’ cannot be created via dependency injection, as it does not have an Angular decorator

If you are getting the following error while adding a service to an Angular module:

The class '...Service' cannot be created via dependency injection, as it does not have an Angular decorator. This will result in an error at runtime.

Either add the @Injectable() decorator to '...Service', or configure a different provider (such as a provider with 'useFactory').

The solution is to add an Injectable decorator at the top of your service. Here is how you can add it.

@Injectable()
export class YourService {
......
}

If you want to use the service for whole project then you can use:

@Injectable({
  providedIn: 'root'
})