0

First of all, I'm a bit too new to Angular 7, I come from Java so I'll be making some silly mistakes.

I have a component that fails to initialise because (maybe) I'm making a call to another function.

 ngOnInit() {
    this.myForm = this.formBuilder.group({
      a: ['', ]
    },
      { validator: this.CheckDetails }
    );
  }

  ngDoCheck() {
    this.CheckDetails(this.myForm); //type FormGroup
  }

  CheckDetails(control: AbstractControl) {
    const aControl = control.get('a'); //<-- 2nd error refers to this line
    const someText = this.generateText(); //<-- 1st error refers to this line
    doThingsWith(someText);
  }
  private generateText(): string {
    return  'My text';
  }

ERROR TypeError: this.generateText is not a function at FormGroup.MyComponent.CheckDetails [as validator]

ERROR TypeError: Cannot read property 'get' of undefined at MyComponent.CheckDetails

Initialises all right when CheckDetails looks like this:

CheckDetails(control: AbstractControl) {
    const aControl = control.get('a');
    const someText = 'My text';
    doThingsWith(someText);
  }

I'm aware of my lack of knowledge in Angular.

UncleDave
  • 6,872
  • 1
  • 26
  • 44
Neikon
  • 169
  • 1
  • 10

0 Answers0