When I am trying to call one .ts file from another using .Form the following error is occurring

Uncaught (in promise): TypeError: this.Form is undefined

The file that has an error in it

have imported the .ts file to which i want to pass value from this file

import { SawtoothService } from '../sawtooth.service';

Declared Form using a constructor

constructor ( private Form : SawtoothService ) {}

The Function in which another component file function is called

  async addForm() {

     const proc ="VRT"
     const action ="add"
     const FAMILYNAME = 'abc' 
     const servDt =await this.Form.sendData(this.Gender,this.idproof,this.date,this.firstName,proc,action,FAMILYNAME)
     this.servicedata="this is service data"+servDt;
     alert('SUCCESS!! :-)\n\n' + this.servicedata)   
  }

there is a function sendData in sawtooth.service.ts file i want to pass data from this file to that file

2 Answers

0
mbojko On

Depending on how addForm is called, it could be the matter of this context. Try converting it to an async arrow function:

  addform = async () => {
0
Ikechukwu Eze On
    const servDt = await 
 this.Form.sendData(this.Gender,this.idproof,this.date,this.firstName,proc,action,FAMILYNAME)

should be

    const servDt = await this.SawtoothService.sendData(this.Gender,this.idproof,this.date,this.firstName,proc,action,FAMILYNAME)

Even though I can't see the rest of the code in this present file. Normally you'd inject the service in your constructor, then you can then call this.name_of_service.any_method_you_created_on_it