// Updated along the discussion
I try to get JSON objects(Tasks) via http request and parse them into my own class to display them on my HTML page(Task Overwiew).
This is what I get:
This is the json array my php returns:
{"result":[{"id":"3","znumber":"vor21423"},{"id":"2","znumber":"vor213"}]}
Here's my last try from the turtorial on angular.io. I've tested many answers but most of them relate to .json() which is no longer part of the HTML client.
export class ApiComponent {
private apiUrl = 'http://localhost:81/work/get.php';
results: Steve[];
constructor(private http: HttpClient) {
}
ngOnInit() {
this.getSteves();
}
getSteves() {
this.http.get<ItemsResponse>(this.apiUrl)
.subscribe(data => {
this.results = data.result
.map(steve => new Steve(steve.id, steve.zNumber));
console.log(this.results);
console.log(data);
});
}
}
The Interface
import { Steve } from './Steve';
export interface ItemsResponse {
results: Steve[];
}
HTML
<div>
<div *ngFor="let steve of results">
<p> - {{steve.id}}</p>
<p> - {{steve.zNumber}}</p>
</div>
</div>
The Steve Class
export class Steve {
public id = 0;
public zNumber = '';
constructor(id: number, zNumber: string) {
this.id = id;
this.zNumber = zNumber;
}
}
The API
<?php
require_once('db.php');
$sql = 'SELECT * FROM jobs ORDER BY id DESC';
$result = $conn->query($sql);
if ($result->num_rows > 0) {
$data = array();
while($row = $result->fetch_assoc()){
$data[] = $row;
}
echo json_encode(array('result' => $data));
} else {
echo 0;
}
?>

dataobject while debugging I believe you should useresultnotresults.resultsis a variable and as such, can be named anyway you want. The conventions is to use singular, soresult. It looks likedataobject coming from the server has nostevesproperty.