ngbModal open()参数传递
子页面
import { Component, Output, EventEmitter } from '@angular/core'; export class AppModalComponent { private data: string; @Output emitService = new EventEmitter(); constructor() { this.data = "hello world"; }
ngOnInit(){
// 坑,父传子的数据,在init中可以获取, constructor()无法获取
} addMe() { this.emitService.next(this.data) } }
父页面
openModal() { const modalRef = this.modalService.open(AppModalComponent);
// 父传子
modalRef.componentInstance.data = 'hi';
// 子传父: modalRef.componentInstance.emitService.subscribe((emmitedValue) => { // do sth with emmitedValue }); }