I have this table with a select option in each row,
and according to ‘dataType’ in each row the value of select option will change.
Table Array:
{
'name':'Name',
'count': 22,
'dataType':'numerical'
}
{
'name':'Name',
'count': 44,
'dataType':'string'
}
]
select option array :
{
'numerical':['1', '2', '3'],
'string':['a', 'b', 'c'],
}
2
Answers
it’s equal in a table or in a div (unless you use mat-table or another library to show a table)
But (always there are a but) remember use [(ngModel)] or use ReaciveForms if you want to "store" the values selected in variables of the .ts. It’s impossible know what are you try to do with your brief explain of the question
You can accomplish this task using Angular by dynamically changing the options available in each select dropdown based on the ‘dataType’ of each row.
1. HTML Template:
Create a table and, for each row, create a select dropdown whose options are determined by the ‘dataType’.
2. Angular Component:
getOptions()
to return the correct options array based on the ‘dataType’.Explanation:
getOptions(dataType: string)
in the component takes adataType
as an argument and returns the corresponding array of options fromselectOptions
.tableArray
to create rows in the table.getOptions(item.dataType)
, and this is how we dynamically assign options based on ‘dataType’.Run this code in your Angular environment, and you should see a table with select options that change based on the ‘dataType’ in each row.