【发布时间】:2018-02-14 23:35:04
【问题描述】:
我尝试在下面的代码中将数据从模态组件传递到父组件。
package.json
"@ng-bootstrap/ng-bootstrap": "^1.0.0-beta.3"
app.component.html
<button class="btn btn-primary" (click)="openModal()">Open</button>
app.component.ts
import { NgbModal, NgbActiveModal } from '@ng-bootstrap/ng-bootstrap';
export class AppComponent {
constructor(private modalService: NgbModal) { }
openModal() {
const modalRef = this.modalService.open(AppModalComponent);
}
}
app-modal.component.html
<h1>{{data}}</h1>
<button class="btn btn-primary" (click)="addMe()"></button>
app-modal.component.ts
import { Component, Output, EventEmitter } from '@angular/core';
export class AppModalComponent {
private data: string;
@Output emitService = new EventEmitter();
constructor() {
this.data = "hello world";
}
addMe() {
this.emitService.next(this.data)
}
}
emit之后,如何获取父组件(app.component)的数据??
【问题讨论】:
标签: angular ng-bootstrap