0

I want to show the list of tickets in my Angular frontend. I mean to show ticketId and place like on the picture below.

Here is my request from http://localhost:8080/api/customers

enter image description here

Here is the result in http://localhost:4200/customer

Unfortunately list of tickets is empty. I don't know how to show it.

enter image description here

Here is my class customer-details.component.html

<div *ngIf="customer">
<div>
<label>Name: </label> {{customer.name}}
</div>
<div>
<label>Surname: </label> {{customer.surname}}
</div>
<div>
<label>List of tickets: </label> {{customer.tickets}}
</div>
<span class="button is-small btn-danger"  (click)='deleteCustomer()'>Delete</span>
<hr/>
</div>

My class customers-list.component.html

<div *ngFor="let customer of customers | async" style="width: 300px;">
<customer-details [customer]='customer'></customer-details>
</div>

<div>
<button type="button" class="button btn-danger" (click)='deleteCustomers()'>Delete all</button>
</div>

Class customer.service.ts

export class CustomerService {

private baseUrl = 'http://localhost:8080/api/customers';

constructor(private http: HttpClient) {
}

getCustomersList(): Observable<any> {
return this.http.get(`${this.baseUrl}`);
}

My class customer.ts

export class Customer {
customerId: number;
name: string;
surname: string;
tickets: Ticket[];
}
export class Ticket {
ticketId: number;
place: number;
customerId: number;
flightId: number;
}

Class customers-list.component.ts

export class CustomersListComponent implements OnInit {

customers: Observable<Customer[]>;

constructor(private customerService: CustomerService) { }

ngOnInit() {
this.reloadData();
}

reloadData() {
this.customers = this.customerService.getCustomersList();
}
}

2 Answers 2

1

According to the picture of the json response the property is called ticket, not tickets. So you want to either rename it (since it's clearly a misnomer) or iterate accordingly:

*ngFor="let ticket of customer.ticket"
Sign up to request clarification or add additional context in comments.

Comments

1

In your customer-details.component.html you have to iterate on your ticket.

You can try something like this :

<div>
  <label>List of tickets: </label>
  <div *ngFor="let ticket of customer.ticket">
    {{ ticket.ticketId }}
    {{ ticket.place }}
  </div>
</div>

1 Comment

unfortunately, it's still empty

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.