Please assist . I have the following table in stackblitz or stackblitz 2. The component of the table is as follows :
export class AppComponent {
gender = [
{ id: 1, value : 'Female' },
{ id: 2, value : 'Male' }
];
age = [
{ id: 1, value: 'Adults' },
{ id: 2, value: 'Children' },
{ id: 3, value: 'Creatures' },
{ id: 5, value: 'Youth' }
];
color = [
{ id: 1, value: 'Black' },
{ id: 2, value: 'White' },
{ id: 3, value: 'Brown' },
];
}
The View of the table is as follows :
<div *ngFor="let gender of gender; let g = index;">
<table class="table-bordered">
<tr>
<td>
<span>{{gender.value}}</span>
</td>
<td>
<table class="table-bordered">
<tr *ngIf="g === 0">
<td>Age</td>
<td *ngFor="let color of color; let r = index;">{{ color.value }}</td>
</tr>
<tr *ngFor="let age of age; let a = index;">
<td>{{ age.value }}</td>
<td>
<input [id]="" type="text" #black />
</td>
<td>
<input [id]="" type="text" #white />
</td>
<td>
<input [id]="" type="text" #brown/>
</td>
</tr>
</table>
</td>
</tr>
</table>
</div>
I can get data from the view to the component using ViewChildren like @ViewChildren(brown) brown: QueryList<elementRef>; since i added #brown. According to angular doc using ElementRef can result to some security risks.
Question: How can get data from component to view when i have such a table and is ther a better way to get data from the view to the component without using ViewChildren or ViewChild ?
If i have to introduce reactive forms to the table how can i implement it ?
Your help is much appreciated. Thank You.