My Mockup-data has a structure similar to this:
"data": {
"name": "rowValue1",
"hours": [
{
"year": 2018,
"month": "October",
"number1": 100,
"number2": 80,
"diff": 20
},
{
"year": 2018,
"month": "November",
"number1": 100,
"number2": 80,
"diff": 20
},
{
"year": 2018,
"month": "December",
"number1": 100,
"number2": 80,
"diff": 20
},
{
"year": 2019,
"month": "January",
"number1": 100,
"number2": 80,
"diff": 20
}
]
}//...
When iterating through the column-objects to build a header, I need to extract values from my data based on certain criteria. Each column must have the fields: month
, year
, and a field
which could be number1
, number2
, or diff
. In order to extract the correct value from my hours
-array, I tried using the Array.find()
method within my HTML code.
https://i.sstatic.net/3Zww4.png
The goal is to identify the right entry in the array based on the provided parameters. For instance, instead of having the value for number1
, I want to fetch the exact element from the hours
array, such as 100
in the example above. The attempt to use Array.find()
resulted in an error when running ng serve
:
Uncaught Error: Template parse errors: Parser Error: Bindings cannot contain assignments at column 27 in [{{rowdata.hours.find(entry => entry.year == col.year && entry.month == col.month)[col.field]}}] in
This indicates that there might be a problem with the assignment inside the arrow function entry => (...)
. Is there an alternative approach to finding the correct entry in the array?