<chained-item-list [items]="items" (onRemoveItem)="onRemoveItem($event)"> <div class="card"> <h4>Header Item</h4> <small>22/03/2022</small> <p>Lorem ipsum dolor amet.</p> </div> </chained-item-list>
<div class="list-header"> <h3>CHAINED LIST</h3> <button (click)="addNewItem()" type="button" class="btn-add">Add New</button> </div> <ul> <ng-container *ngFor="let item of items; let indexItem = index"> <li> <ng-content></ng-content> <button (click)="removeItem(indexItem)" type="button" class="btn-remove">X</button> </li> </ng-container> </ul>
export class ChainedItemListComponent { @Input() items: any[]; @Output() onRemoveItem: EventEmitter<any> = new EventEmitter(); constructor() {} addNewItem() { this.items.push(Math.floor(Math.floor(Math.random() * 100))); } removeItem(indexItem: number) { try { this.onRemoveItem.emit(this.items.splice(indexItem, 1)[0]); } catch (e) { this.onRemoveItem.emit(e); console.log(e); } } }
var
This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)