I have exported the following class in Typescript:
export class BinSetupComponent implements OnInit {
bins = [
{id: '001', name:'Temper', comment: 'Large Round', type: 'Grain Storage', subtype: 'Screenings', status: 'Active', capacity: '2,000,000'},
{id: '123', name:'Small Valley', comment: 'Rectangle', type: 'Feed Storage', subtype: 'Mill Mix', status: 'Inactive', capacity: '1,300,000'},
{id: '493', name:'Hilltop', comment: 'Hexagonal', type: 'WIP Storage', subtype: 'Flour', status: 'Active', capacity: '1,200,000'},
{id: '004', name:'Large Valley', comment: 'Other', type: 'Loadout', subtype: 'Organic', status: 'Inactive', capacity: '300,000'},
{id: '982', name:'Temper', comment: 'Large Round', type: 'Grain Storage', subtype: 'Screenings', status: 'Active', capacity: '1,000,000'}
];
editingMeasurements: boolean = false;
toggleMeasurements(index) {
this.editingMeasurements = !this.editingMeasurements;
}
constructor() {}
ngOnInit() {
}
}
I am using the boolean variable to show/hide elements on click in each iteration of the ngFor loop. I am wondering how to toggle that variable (with my toggleMeasurements() function on click of a button in each iteration. Currently clicking the button changes the boolean for the entire view and therefore toggles all of my elements. How do I pass the index and only update that variable for the iteration where the button is clicked?
See the example on StackBlitz here...https://stackblitz.com/edit/angular-stahy5