I'm having trouble with this code. Every time I run it, the console throws a type error saying it can't read property sort. Does anyone have any ideas on how to fix this?
import { Component, OnInit, Input } from '@angular/core';
import { Order } from 'src/app/models/order';
@Component({
selector: 'app-table',
templateUrl: './table.component.html',
styleUrls: ['./table.component.css']
})
export class TableComponent implements OnInit {
@Input() orders: Order[];
sortedOrders: Order[];
constructor() { }
ngOnInit(): void {
this.sortedOrders = this.sortOrders(this.orders);
console.log(this.sortedOrders);
}
sortOrders(orders: Order[]): Order[] {
return orders.sort((a, b) => a.personName.localeCompare(b.personName));
}
}