Currently, I am following a video tutorial which also has a text version. Despite copying the code exactly as shown in the tutorial, I encountered the following error:
Error TS2339: Property 'getEmployees' does not exist on type 'EmployeeService'
After searching online and checking out several related questions on platforms like Stack Overflow such as this one, here, that one and another link, along with numerous similar issues reported on GitHub.
Service:
//import statements go here ...
@Injectable()
export class EmployeeService {
private listEmployees: Employee[] = [
{
//dummy data removed for brevity.
},
];
getEmployees(): Employee[] {
return this.listEmployees; //ERROR in src/app/employees/list-employees.component.ts(14,44)
}
}
Component class:
//import statements
@Component({
selector: 'app-list-employees',
templateUrl: './list-employees.component.html',
styleUrls: ['./list-employees.component.css']
})
export class ListEmployeesComponent implements OnInit {
employees: Employee[];
constructor(private _EmployeeService: EmployeeService) { }
ngOnInit() {
this.employees = this._EmployeeService.getEmployees();
}
}
I have imported the service in my app.module.ts
file and added it to the providers array of ngModule
.
Despite these efforts, I am still unable to resolve the error or comprehend its root cause.