[英]How to pass data fetched from http, from a Mat-Dialog Component to a Parent component in angular 6?
[英]Pass dynamic object key in mat-dialog angular
我正在使用 angular 材料的 mat-dialog。 這是我的代碼:
if(abc_name === name){
const dialogRef = this.dialog.open(ViewAbcComponent, {
panelClass: 'full-screen-dialog-container',
data: {abc_name: this.abcDetails.item1[keyValue]}
});
dialogRef.afterClosed().subscribe((result) => {
if(result){}
console.log("ViewAbcComponent dialog closed", result);
});
}
在data:
object 我想要 tp 傳遞動態abc_name
值。 知道如何實現嗎?
您可以在服務中創建主題/行為主題,並在您的 ViewAbcComponent 組件中收聽(訂閱)該主題。 一旦您的數據發生更改,您必須將數據更新為subject.next(data);
你會在組件中得到它。 主題示例:
const subject = new Rx.Subject();
subject.next(1);
subject.subscribe(x => console.log(x));
行為主體示例:
const subject = new Rx.BehaviorSubject(0);
subject.next(1);
subject.subscribe(x => console.log(x));
詳細說明:(根據要求)
1.您必須在服務中添加變量,比如說app.service.ts並添加更新方法。
const subject = new Rx.Subject();
updateSubject(data){
subject.next(data)
}
無論您的數據在哪個組件中更改,您都必須調用此 updateSubject 方法來更新數據。 像這樣this.appService.updateSubject(updatedData);
在ViewAbcComponent組件中,您已經訂閱了它
this.appService.subject.subscribe(x => console.log("mydata",x));
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.