Вот мой файл app.comComponent.ts:
export class AppComponent implements OnInit {
public employees: Employee[] | undefined;
constructor(private employeeService: EmployeeService) {}
ngOnInit(): void {
this.getEmployees();
}
public getEmployees(): void {
this.employeeService.getEmployees().subscribe(
(response: Employee[]) => {
this.employees = response;
},
(error: HttpErrorResponse) => {
alert(error.message);
}
)
}
}
А вот мой файл сотрудника.service.ts:
@Injectable({
providedIn: 'root',
})
export class EmployeeService {
private apiServerUrl = environment.apiBaseUrl;
constructor(private http: HttpClient) {}
public getEmployees(): Observable {
return this.http.get(`${this.apiServerUrl}/employee/all`);
}
public addEmployee(employee: Employee): Observable {
return this.http.post(
`${this.apiServerUrl}/employee/add`,
employee
);
}
public updateEmployee(employee: Employee): Observable {
return this.http.put(
`${this.apiServerUrl}/employee/update`,
employee
);
}
public deleteEmployee(employeeId: number): Observable {
return this.http.delete(
`${this.apiServerUrl}/employee/delete/${employeeId}`
);
}
}
А вот вывод терминала из серверной части:
GET http ://localhost:8082/employee/all
HTTP/1.1 200 Content-Type: application/json Transfer-Encoding:
chunked Дата: пятница, 27 января 2023 г. 16: 00:06 GMT Поддержка активности: timeout=60
Соединение: поддержка активности
[ {
"id": 5,
"name" : "Миллард Герхарц",
"email": "mgerhartz0@so-net.ne.jp",
"jobTitle": "Аналитик по развитию бизнес-систем",
"phone": " 487-530-7589",
"imageUrl": "https://img.freepik.com/free-photo/clos ... al-outfit- Against-blue-background_1258-66609.jpg?w=2000",
"employeeCode": "4d6ca12b-94fc-4d64-8ea3-d4c3e2cfdfc3" }, {
"id": 6,
"имя": "Теренсио Стоате",
"электронная почта": "tstoate0@howstuffworks.com",
"jobTitle": "Аналитик по бюджету/бухгалтерскому учету II",
"телефон": "936-713-6713",
"imageUrl": "

"employeeCode": "a0154f0f-5e8e-4456-8cb6 -93f693dbf462" } ]
Код ответа: 200; Время: 157 мс; Длина контента: 610 байт
It seems like employees list is always empty
Подробнее здесь: https://stackoverflow.com/questions/752 ... l-0-unknow