如何从角度2中获取MdDialog到基本分量的变量值?

时间:2017-05-03 03:42:38

标签: node.js angular ubuntu

我在角度2工作。 我有两个组件,一个是我的表单,另一个是我的对话框&当我单击表单中的按钮时,我将得到一个对话框,其中包含复选框并返回变量中已选中复选框的值。 现在我的问题是我想在表单组件中访问对话框组件的变量。

1。马达周期package.component.ts

SUM()

2。 form.service.ts

moterCyclePackages = 
    [ { "name": "P1", "value":"P1", "price": "20","state": false}, 
    { "name": "P2", "value":"P2", "price": "30", "state": false}, 
    { "name": "P3", "value":"P3", "price": "40", "state": false} 
]; 
constructor(public dialogRef: MdDialogRef<MotorCyclePackageComponent>) { }

第3。用户form.Component.ts

 constructor(private http: Http, private dialog: MdDialog) { }
 public motorCyclePackage(): Observable<boolean>{
     let motorCycleRef: MdDialogRef<MotorCyclePackageComponent>;
     motorCycleRef = this.dialog.open(MotorCyclePackageComponent);
     console.log(motorCycleRef);
     return motorCycleRef.afterClosed();
 }

1 个答案:

答案 0 :(得分:1)

  • 假设您想要访问此属性WriteNative(),您可以执行以下操作:A.cpp

<强> 2。 form.service.ts

moterCyclePackages
  • 如果你想在模态关闭时获取数据,你可以将数据放到关闭方法

<强> 1。马达周期package.component.ts

componentInstance

第3。用户form.Component.ts

public motorCyclePackage(): Observable<boolean>{
    let motorCycleRef: MdDialogRef<MotorCyclePackageComponent>;
    motorCycleRef = this.dialog.open(MotorCyclePackageComponent);
    console.log(motorCycleRef.componentInstance.moterCyclePackages); // this one
    return motorCycleRef.afterClosed();
}