I have a main component in which there are two components: headerTable, rowTable.
In headerTable, my table column naming is the checkbox, which, when checked, selects all the rows in rowTable (and vice versa). In rowTable there is also a checkbox (it is this checkbox that will stand out to select a row). I want to do the following script:
- Click on the selection of all lines (in the headerTable click on the checkbox), and remove from the selection any of the lines.
- After I remove the checkbox in any line, the headerTable should remove the checkbox.
I tried to do this through the decorator Input, but apparently, because of different contexts, then the input does not work.
@Component({ selector: 'headerTable', template: '<input type="checkbox" [ngModel]="allItems" (ngModelChange)=onChange($event)>' }) export class HeaderComponent { @Input() allItems: boolean; onChange(flag: boolean) { this.allItems = flag; } } ... @Component({ selector: 'row', template: '<input type="checkbox" (change)="onChange($event)">' }) export class RowComponent { @Output() checkedItem = new EventEmitter<number>(); onChange(flag: boolean) { this.checkedItem.emit(5); } } ...
page.html:
<headerTable [allItems]="allItems"></headerTable> <row (checkedItem)="checkedItem($event)"></row>
page.ts:
checkedItem(id: number) { this.allItems = false; }