【问题标题】:Uncaught (in promise): TypeError: this.Form is undefined error in angular 6未捕获(承诺):TypeError:this.Form is undefined error in angular 6
【发布时间】:2019-04-20 20:49:42
【问题描述】:

当我尝试使用 .Form 从另一个调用一个 .ts 文件时,发生以下错误

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

其中有错误的文件

已导入我想从该文件传递值的 .ts 文件

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

使用构造函数声明表单

构造函数(私有形式:SawtoothService){}

调用另一个组件文件函数的函数

  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)   
  }

sawtooth.service.ts 文件中有一个函数 sendData 我想将数据从这个文件传递到那个文件

【问题讨论】:

  • 在你的代码中包含这个类的构造函数
  • @IkechukwuEze 添加

标签: javascript angular angular6 angular7


【解决方案1】:

根据addForm 的调用方式,可能是this 上下文的问题。尝试将其转换为异步箭头函数:

  addform = async () => {

【讨论】:

  • this.addForm() 这就是我调用 addForm() 的方式
【解决方案2】:
    const servDt = await 
 this.Form.sendData(this.Gender,this.idproof,this.date,this.firstName,proc,action,FAMILYNAME)

应该是

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

即使我看不到当前文件中的其余代码。通常你会在你的构造函数中注入服务,然后你可以调用this.name_of_service.any_method_you_created_on_it

【讨论】:

    猜你喜欢
    • 2019-03-08
    • 1970-01-01
    • 1970-01-01
    • 2017-11-24
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多