'new version of subscribe() in angular

I'm new to Angular, and I try to build a web following a tutorial. But it said the way I use subscribe is too old, could you help me to change it?

**
employees: Employee[] = []
  constructor(private employeeService: EmployeeService){}
  public getEmployees():void {
    this.employeeService.getEmployees().subscribe(
      (res:Employee[])=>{
        this.employees = res
      },
      (error:HttpErrorResponse)=>{
        alert(error.message)
      }
    )
  }
**


Solution 1:[1]

I'm also new to Angular and ran into the same issue. I think the problem is just syntax. There need to be curly braces surrounding the subscribe parameters. Also, at the beginning of the response handler, add "next:" and at the beginning of the error handler, add "error:"

this.employeeService.getEmployees().subscribe({
  next: (res:Employee[])=>{
    this.employees = res
  },
  error: (error:HttpErrorResponse)=>{
    alert(error.message)
  }
})

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 Kelly H