You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
A common use case, is to display an Asterix next to a required field label, or a message bellow a field. We would ideally want to implement this behavior once for our design system, so that it will work with all custom controls.
<!-- consumer.html --><app-text-fieldlabel="Name"
[form]="nameForm"
/><!-- text-field.component.html --><app-field-frame><app-form-label>{{label}}</app-form-label>
... <!-- text field implementation --></app-field-frame>
The difference is that in the first use case the form directive is used as a child of the component in which we want to access it form, and the second use-case the form directive is a parent of the component we want to access it from.
Accessing form of parent
To access the form of a parent, you can use the utility injectForm(). It will return a Form object if there is a parent that uses it. If there is more than one, it will return the first one from the bottom.
Now, for example, if you want to check whether the form is required, you can do this:
Binding Validation Information to View
A common use case, is to display an Asterix next to a required field label, or a message bellow a field. We would ideally want to implement this behavior once for our design system, so that it will work with all custom controls.
There are two possible architectures here:
Field wrapper:
Label inside the field:
The difference is that in the first use case the form directive is used as a child of the component in which we want to access it form, and the second use-case the form directive is a parent of the component we want to access it from.
Accessing form of parent
To access the form of a parent, you can use the utility
injectForm()
. It will return aForm
object if there is a parent that uses it. If there is more than one, it will return the first one from the bottom.Now, for example, if you want to check whether the form is required, you can do this:
The text was updated successfully, but these errors were encountered: