how to change tr color according to the value from array in Angular

can someone please help me with some code, i have an array of objects with different data in it and then i display it in a table using *ngfor, so now i want to write a code that will check if delivery_to is less than current time it must turn that row red. so for every row that the delivery_to is less than current time it should turn red. here is my array of objects

var array1 = [{
"order_id": "241918",
"customer_name": "Marietjie",
"customer_surname": "Short",
"total_items": "44",
"completed_items": "17",
"percent_complete": "38.64",
"datetime_received": "2018-07-25 15:18:25",
"delivery_date": "2018-10-29",
"delivery_from": "12:00",
"delivery_to": "13:00",
"completed": "0",
"shopper": "joel"
},
{
"order_id": "281774",
"customer_name": "Ashleigh",
"customer_surname": "Hodge",
"total_items": "16",
"completed_items": "0",
"percent_complete": "0.00",
"datetime_received": "2018-10-04 15:59:19",
"delivery_date": "2018-10-29",
"delivery_from": "12:00",
"delivery_to": "13:00",
"completed": "0",
"shopper": null
},
{
"order_id": "232777",
"customer_name": "Charisse",
"customer_surname": "Bowles",
"total_items": "30",
"completed_items": "0",
"percent_complete": "0.00",
"datetime_received": "2018-07-24 17:28:22",
"delivery_date": "2018-10-29",
"delivery_from": "16:00",
"delivery_to": "17:00",
"completed": "0",
"shopper": null
}
]

here is what i tried but for some reason its turning all the tr red

array1.forEach(function(element) {
if (element.delivery_to === "17:00") {
    colortest = 'red';
}

});

Source: Angular

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.