Home > Net >  How can I compare two object in angular? Prevoiusly I have the same name of form comtrol but it is i
How can I compare two object in angular? Prevoiusly I have the same name of form comtrol but it is i

Time:02-04

Prevoiusly I have two object with difference fromGroupName but in fromGroup I have the same fromControlName

Like in the picture

this is the respond API that I have to compare

 I want to compare the formcomtrolName of oldAuditLog(formGroupName) to the fromControlName of newAuditLog(formGroupName)

CodePudding user response:

So you have two forms and each form is named something different. You can extract the data from each form and use object notation to compare values.

  1. extract data from form (replace 'formControlGroup' with the form group you defined in your code): const oldAuditLog = this.formControlGroup.value
  2. you now have the data from your form, you can then reference the property you want to compare and compare them! console.log(oldAuditLog.ruleName) should output "RuleName ", as per your attachment.

Let me know if this helps!

CodePudding user response:

if(obj?.['oldAuditLog']?.['ruleName']==obj?.['newAuditLog']?.['ruleName']){ console.log('True') }

  • Related