title: Angular 9 - Cannot read property of undefined
body: <p>I am running an application using Angular CLI 9.0.7. In this application there is a form with a field that needs to have its control digit validated. For this, I created a Custom Validator.</p>
  
  <p>When the field on the form is changed, the Custom Validator is activated to check the consistency.</p>
  
  <p>The Custom Validator component, needs to call a method that is in another class and that is shared by other components, and when it is going to execute this line I get the message Cannot read property '<strong>isCpf</strong>' of undefined.</p>
  
  <p>I copied what is called inside the custom validator, and passed, but this is not correct, it sucks.</p>
  
  <p>How can I do to call the method isCpf correctly and using good practices?</p>
  
  <p><strong>This is my Custom Validator</strong></p>
  
  <pre><code>    static cpfValido(control: AbstractControl): any | null {
          const cpf: string = control.value;
  
          if (cpf === '') {
              return null;
          }
          else {
              if (this.isCpf(cpf)) {  // When isCpf is called throw Cannot read property 'isCpf' of undefined
                  null;
              }
              else {
                  return { 'cpfValido': false };
  
              }
          }
      }
  </code></pre>
  
  <p>and in the same file this is a called method</p>
  
  <pre><code>    private static isCpf(pNumeroCpf: string): boolean {
          if (!pNumeroCpf) return false;
  
          let nro: string = this.preencherComCaracterEsquerda(this.removerFormatacao(pNumeroCpf), this.SIZE_CPF, '0');
          let j: number = 0;
          let peso: number = 2;
          let soma: number = 0;
          let dvc: number[] = [0, 0];
          let dvi: number[] = [0, 0];
  
          if (this.temCaracterRepetido(nro)) return false;
  
          for (j = 0; j &lt; 2; j++) {
              peso = 2;
  
              soma = this.aplicarPeso(nro.substring(0, nro.length - 2 + j), peso, 11);
  
              dvc[j] = (soma % 11) &lt; 2 ? 0 : 11 - (soma % 11);
          }
  
          dvi[0] = parseInt(nro.charAt(nro.length - 2), 10);
          dvi[1] = parseInt(nro.charAt(nro.length - 1), 10);
  
          return (dvi[0] === dvc[0] &amp;&amp; dvi[1] === dvc[1]);
      }
  
  </code></pre>