I have prepared a directive that should be set on each formControl that is checking if given formControl contains a required validator. More or less based on this: Angular FormControl check if required but wrapped into directive.
Now I am stuck on problem of finding closest label element to add special class to it. I started with getting this.el.nativeElement.previousSibling and appending class via renderer2 but then I noticed that not every input in my app is the same and I have 2 cases possible:
<div>
<label></label>
<input directive></input>
</div>
or
<div>
<label></label>
<div>
<input directive></input>
<span></span>
</div>
</div>
How to get closest label to my input? Tried using webAPI's closest function but it seems not working and returning null unless I am calling it on wrong object (tried both - this.el and this.el.nativeElement).
Or is my apprach totally wrong and it should be done somehow else?