I am working on creating a for()
loop to check the first field in my template with the status INVALID and I need to retrieve the name of this object.
This is what I have tried so far:
for(var mandatoryField in form.controls){
if(form.controls[mandatoryField].status == "INVALID"){
var displayedMandatoryField = form.controls[mandatoryField];
console.log(displayedMandatoryField)
return ;
}
}
It seems like my logic is correct, but I am not able to get the name of my object in this line:
var displayedMandatoryField = form.controls[mandatoryField];
I want to traverse the DOM tree to find the object with the status INVALID, but I only need its name. For example: height, length, etc...
https://i.sstatic.net/abz2V.png
Any suggestions on how can I achieve this?