What I'm trying to achieve is automatically set a asterisk on a input when a given control has the validation rule 'required'.
Component ts:
this.form = this.fb.group({
name: ['', [Validators.required]]
});
Component template:
<label>
<span>Name</span>
<input type="text" [appRequiredAsterisk]="form.get('name')" formControlName="name" id="name">
</label>
My Directive:
@Directive({
selector: '[appRequiredAsterisk]'
})
export class RequiredAsteriskDirective implements OnInit {
@Input() appRequiredAsterisk: AbstractControl;
constructor(private el: ElementRef) { }
ngOnInit(): void {
// Append Asterisk here..
}
}
I can't find a way to see if the validation rule 'required' is set on the AbstractControl appRequiredAsterisk
. How can I do this?