我在角度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();
}
答案 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();
}