モーダルコンポーネントからモーダルの親コンポーネントにモーダルイベントを渡したいのですが、何らかの理由でEventEmitterを動作させることができません。誰かがアイデアを持っていれば、それは非常に感謝します。メインコードは、以下の(非稼働)でNG-ブートストラップデモからフォークplunkここにある:http://plnkr.co/edit/xZhsqBV2mQaPxqFkoE7C?p=previewイベントエミッタがブートストラップモーダルから親に
app.ts
@Component({
selector: 'my-app',
template: `
<div class="container-fluid" (notifyParent)="getNotification($event)">
<template ngbModalContainer></template>
<ngbd-modal-component ></ngbd-modal-component>
</div>
`
})
export class App {
getNotification(evt) {
console.log('Message received...');
}
}
モーダルcomponent.ts
import {Component, Input, Output, EventEmitter} from '@angular/core';
import {NgbModal, NgbActiveModal} from '@ng-bootstrap/ng-bootstrap';
@Component({
selector: 'ngbd-modal-content',
template: `
<div class="modal-body">
<p>Hello, {{name}}!</p>
</div>
<div class="modal-footer">
<button type="button" class="btn btn-secondary" (click)="activeModal.close('Close click')">Close</button>
<button type="button" class="btn btn-secondary" (click)="notify()">Notify</button>
</div>
`
})
export class NgbdModalContent {
@Input() name;
@Output() notifyParent: EventEmitter<any> = new EventEmitter();
constructor(public activeModal: NgbActiveModal) {}
notify(){
console.log('Notify clicked...');
this.notifyParent.emit('Here is an Emit from the Child...');
}
}
@Component({
selector: 'ngbd-modal-component',
templateUrl: 'src/modal-component.html'
})
export class NgbdModalComponent {
constructor(private modalService: NgbModal) {}
open() {
const modalRef = this.modalService.open(NgbdModalContent);
modalRef.componentInstance.name = 'World';
}
}
これをチェックしてください[**回答**](http://stackoverflow.com/questions/42460418/angular-2-ng2-bootstrap-modal-inside-child-component-called-from-parent-componen/42463516#42463516) – Aravind