send EventEmitter from child component <ng-content>

1.9k views Asked by At

I have this structure

<accordion>
    <accodrion-item>
        <accordion-head [title]="'Header 1'"></accordion-head>
    </accordion-item>
</accordion>

@Component({
    selector: 'accordion-head',
    template: '<h3 (click)="toggleItem($event)">{{ title }}</h3>
})

export class AccordionHead {
    @Input() title;
    @Output() handleToggleItem = new EventEmitter();

    toggleItem() {
      this.handleToggleItem.emit(this);
    }
}

@Component({
    selector: 'accordion-item',
    template: '<ng-content></ng-content>'
})

@Component({
    selector: 'accordion',
    template: '<ng-content></ng-content>'
})

I want to listen on handleToggleItem in AccordionItem/Accordion component. How to do this? I dont want to use any service.

0

There are 0 answers