I am a newbie in angular2/4. I want to build shared modals with dynamic body and footer, then listen to which button of the footer that the user has pressed. I was inspired by the contribution of @echonax in plunker, I edited it as follows. I bound the button to eventEmitters
Template:
<div class="modal fade" id="theModal" tabindex="-1" role="dialog" aria-labelledby="theModalLabel">
<div class="modal-dialog largeWidth" role="document">
<div class="modal-content">
<div class="modal-header">
<h4 class="modal-title" id="theModalLabel">The Label</h4>
</div>
<div class="modal-body" #theBody>
</div>
<div class="modal-footer">
<button class="btn btn-primary" (click)="submit()">save</button>
<button class="btn btn-primary" (click)="edit()">edit</button>
<button type="button" class="btn btn-default">Close</button>
</div>
</div>
</div>
</div>
Component:
@Output() modalOutput: EventEmitter = new EventEmitter();
edit() {
if (this.cmpRef) {
this.cmpRef.destroy();
}
this.cmpRef = null;
$('#theModal').modal('hide');
this.modalOuput.emit('edit');
}
submit() {
if (this.cmpRef) {
this.cmpRef.destroy();
}
this.cmpRef = null;
$('#theModal').modal('hide');
this.modalOuput.emit('submit');
}
and in the index.html:
<modal-comp (modalOutput)="modalData($event)"></modal-comp>
I used eventEmitter to catch the pressed button but I dont know how to listen to that event from the component which launched the modal.