import { Output, EventEmitter } from '@angular/core';
@Output() itemSelectEvent= new EventEmitter<string>();
select(array_item){
itemSelectEvent.emit(array_item.id);
}
<app-item-desc *ngFor="let itemDesc of addedItem; let i = index" [itemlistDesc]="itemDesc" (itemSelectEvent)="selectEventHandler($event)"></app-item-desc>
selectEventHandler(event){
// event, you will get selected id here
for(let i=0;i < addedItem.length;i++){
if(addedItem[i].id == event){
addedItem[i]['is_active'] = true;
}else{
addedItem[i]['is_active'] = false;
}
}
}
<div class="order" (click)="select($event)" [ngClass]="{'active': itemlistDesc.is_active}">
</div>
<ul id="grouplist" class="list-group">
<li class="list-group-item" [ngClass]="{'active': selectedItem == item}" (click)="listClick($event, item)" *ngFor="let item of groups">
{{ item.name }}
</li>
</ul>
listClick(event, newValue) {
console.log(newValue);
this.selectedItem = newValue; // don't forget to update the model here
// ... do other stuff here ...
}