I have an angular application using the following model class:
export interface Product {
id: number;
name: string;
currentPrice: number;
orders?: Order[];
lastUpdate?: Date;
}
export interface Order {
orderId: string;
qty: number;
amount: number;
}
I would like to add a note on UI when user adds an order. However, angular does not fire change detection without updating object reference of the product.
Replicated on: https://stackblitz.com/edit/ag-grid-angular-use-gridoptions-k75cr8?file=src/app/order.component.ts
"Add Order" button does not add an entry of "Product / Order updated on hh:mm:sss". "Add Order & Change reference" button adds an entry of it.
Why do I need to update reference of the model to fire change detection? (why does the order table still gets updated without triggering change detection on click of "Add Order" button)
addOrder.OnPushwill not detect it. However, in that case, you can callChangeDetectionRef.detectChanges()manually in the code, at the moment you want Angular to detect your updates.