I have a component with an event on it like this:
<menu-elem (onClick)="reallyCoolEvent($event)"></custom-component>
Right now, i can trigger my reallyCoolEvent with an EventEmitter from my custom-component.
@Output() onClick= new EventEmitter();
this.onClick.emit(stuff);
Like this, in my other component the function reallyCoolEvent will be called and the stuff will be passed to that function. That works really well!
Now, lets say, I want to copy that component for whatever reason and I want to trigger the same event from the original. Right now, I'm going through my list of onClick and if they macth my criteria I store them in a list that I show somewhere else on the page. When I trigger the onClick from there the event is never triggered.
<menu>
<menu-elem label="Action 1" (onClick)="superCoolEvent($event)"></menu-elem>
<menu-elem label="Action 2" (onClick)="superCoolEvent2($event)"></menu-elem>
<menu-elem label="Action 3" (onClick)="superCoolEvent3($event)"></menu-elem>
</menu>
In menu:
template:
<div>
<ng-content></ng-content>
</div>
<sub-menu *ngFor="let subMenu of subMenus" [style.top]="subMenu.top" [style.left]="subMenu.left" [items]="subMenu.items"></sub-menu>
In sub-menu:
template:
<menu-elem *ngFor="let item of items" [label]="item.label"></menu-elem>
By doing that, I would like to be able to trigger the onClick within the <div class="here"> and still trigger the event from the original template : reallyCoolEvent($event). I don't know if I can do that or not. Of course the onClick is not set because I don't have the data anymore from the template. Or at least, I don't know how to get the data.
The only solution that I have so far, is to duplicate my entries like this:
<menu>
<menu-elem label="1" (onClick)="superCoolEvent($event)"></menu-elem>
<menu-elem label="2" (onClick)="superCoolEvent2($event)"></menu-elem>
<menu-elem label="3" (onClick)="superCoolEvent3($event)"></menu-elem>
<div class="test">
<menu-elem label="1" (onClick)="superCoolEvent($event)"></menu-elem>
<menu-elem label="2" (onClick)="superCoolEvent2($event)"></menu-elem>
<menu-elem label="3" (onClick)="superCoolEvent3($event)"></menu-elem>
</div>
</menu>
And depending of my criteria I can show them or not, but I don't like that way since the template gets too big for nothing.