模型关闭后的角度8组件交互

问题描述 投票:1回答:1

我在仪表板组件中,在仪表板组件中,我有一个模态。在模式中,我将另一个组件称为B-Comp。在B-comp中进行了一些更改之后,我将关闭模式,然后B-comp将关闭,现在它又回到了Dashboard组件中。在仪表板上如何获取B-compo数据更改?

Image of my modal

angular bootstrap-modal
1个回答
2
投票

您可以在BComp中使用@Output()装饰器来传递数据,例如

@Component({
  selector: 'b-component'
})
export class BComponent {
  @Output()
  public close: EventEmitter<any> = new EventEmitter();

  public onClose() {
    this.close.emit(this.myData) 
  }
}

在您的仪表板组件中

dashboard.component.html

<b-component (close)="onMyBComponentClose($event)"></b-component>

dashboard.component.ts

...
public onMyBComponentClose(bData) {
 console.log(bData)
}
...
© www.soinside.com 2019 - 2024. All rights reserved.