Tuesday, 2 May 2017

How to get variable value from MdDialog to base component in angular 2?

I am working in angular 2. I have two components one is for my form and another is for my dialog box & when I have click on button present in form I will get a dialog box which hold the check boxes and return the value of checked check boxes in a variable. Now my question is that I want to access variable of dialog component in form component.

  1. motor-cycle-package.component.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) { }

  2. form.service.ts

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

  3. user-form.Component.ts

    constructor(fb: FormBuilder, private formservice:formService){} public motorCyclePackage() { this.formservice .motorCyclePackage() .subscribe(res => this.result = res); }



via Lakhvir Singh

No comments:

Post a Comment