从子组件<ng-content>发送EventEmitter

时间:2017-01-06 18:34:52

标签: angular eventemitter emit

我有这个结构

<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>'
})

我想听听AccordionItem / Accordion组件中的handleToggleItem。这该怎么做?我不想使用任何服务。

0 个答案:

没有答案