MCPcopy Create free account
hub / github.com/angular/components / _shouldForward

Method _shouldForward

src/material/form-field/form-field.ts:648–698  ·  view source on GitHub ↗

* Determines whether a class from the AbstractControlDirective * should be forwarded to the host element.

(
    prop: 'valid' | 'dirty' | 'touched' | 'pending' | 'untouched' | 'pristine' | 'invalid',
  )

Source from the content-addressed store, hash-verified

646 * should be forwarded to the host element.
647 */
648 _shouldForward(
649 prop: 'valid' | 'dirty' | 'touched' | 'pending' | 'untouched' | 'pristine' | 'invalid',
650 ): boolean {
651 const rawControl = this._control?.ngField || this._control?.ngControl;
652
653 if (!rawControl) {
654 return false;
655 }
656
657 // Note: we could clean this up with something like `control()[prop]`.
658 // We don't do it, because it can cause problems with property renaming.
659 if (isFieldTree(rawControl)) {
660 const control = rawControl();
661
662 if (prop === 'valid') {
663 return control.valid();
664 } else if (prop === 'dirty') {
665 return control.dirty();
666 } else if (prop === 'touched') {
667 return control.touched();
668 } else if (prop === 'pending') {
669 return control.pending();
670 } else if (prop === 'untouched') {
671 return !control.touched();
672 } else if (prop === 'pristine') {
673 return !control.dirty();
674 } else if (prop === 'invalid') {
675 return !control.valid();
676 }
677 return false;
678 } else {
679 const control = rawControl as AbstractControlDirective;
680
681 if (prop === 'valid') {
682 return control.valid!;
683 } else if (prop === 'dirty') {
684 return control.dirty!;
685 } else if (prop === 'touched') {
686 return control.touched!;
687 } else if (prop === 'pending') {
688 return control.pending!;
689 } else if (prop === 'untouched') {
690 return control.untouched!;
691 } else if (prop === 'pristine') {
692 return control.pristine!;
693 } else if (prop === 'invalid') {
694 return control.invalid!;
695 }
696 return false;
697 }
698 }
699
700 /** Gets the type of subscript message to render (error or hint). */
701 _getSubscriptMessageType(): 'error' | 'hint' {

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected