0

In console i am getting data as [object Object]. console.log('data is: '+ (data));

data is:  [object Object]

When i am doing json stringify, console.log('data is: '+ JSON.stringify(data)); I am getting data in this format:

{
"employee":
       { "name":"John", 
         "age":30, 
         "city":"New York" 
      }
}

I have 3 variable name , age and city.I want to get those values from this data in ts file.

name: any;
age: any;
city: any;
constructor(private dialogRef: MatDialogRef<EmployeedetailsComponent>,
@Inject(MAT_DIALOG_DATA) data, private dialog: MatDialog){
   this.name = data.name;
}

this.name = data.name; this is not working. How to get these values.Can anyone please help me with this.

2 Answers 2

2

It should be data.employee.name

Sign up to request clarification or add additional context in comments.

Comments

1

You need change to this.name = data.employee.name;

 constructor(private dialogRef: MatDialogRef<EmployeedetailsComponent>,
@Inject(MAT_DIALOG_DATA) data, private dialog: MatDialog){
   this.name = data.employee.name;
}

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.