I've encountered an issue while working on a tutorial in Angular 18 that seems to be targeted towards an older version of the framework.
Below is my Service class:
export class ProductsService
{
getProducts() : string[]
{
return ["Learning Angular","Pro TypeScript","ASP.NET"];
}
}
I am attempting to utilize this service in my Component class by injecting it into the constructor as shown below:
import { CommonModule } from '@angular/common';
import { Component, OnInit } from '@angular/core';
import { ProductsService } from './products.service';
@Component({
selector: 'app-products',
standalone: true,
templateUrl: './products.component.html',
styleUrl: './products.component.css',
imports: [CommonModule]
})
export class ProductsComponent implements OnInit {
products: string[] = [];
constructor(ps: ProductsService)
{
this.products = ps.getProducts();
}
ngOnInit(): void
{
}
}
The error message I'm facing is: NullInjectorError: NullInjectorError: No provider for ProductsService!
The documentation suggests adding some code into app.module.ts:
https://i.sstatic.net/8MI8GcbT.png
However, since there is no app.module.ts file in this version of Angular, I am unsure where to define this dependency. Any help would be appreciated.