Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/angular/27.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Angular 角度8:错误类型错误:“ptf.getCompositeKey不是函数”_Angular - Fatal编程技术网

Angular 角度8:错误类型错误:“ptf.getCompositeKey不是函数”

Angular 角度8:错误类型错误:“ptf.getCompositeKey不是函数”,angular,Angular,我有一个Angular类来映射从API发送的JSON对象。它可以工作,但当我调用类中定义的方法时,Angular无法将类函数识别为函数 ptf.getCompositeKey() 我试着把它改成静态方法 export class PartialTeamFeature extends TeamFeature { id: number; teamFeatureOID?: string; scrumTeam?: DbScrumTeam; sprint?: DbIteration;

我有一个Angular类来映射从API发送的JSON对象。它可以工作,但当我调用类中定义的方法时,Angular无法将类函数识别为函数

ptf.getCompositeKey()
我试着把它改成静态方法

export class PartialTeamFeature extends TeamFeature {
  id: number;
  teamFeatureOID?: string;
  scrumTeam?: DbScrumTeam; 
  sprint?: DbIteration; 
  estimatedTime?: number;

  TeamFeature: TeamFeature;
  ScrumTeam: ScrumTeam;

  // fields that have to be figured out in fr
  ParentTeamFeature?: TeamFeature;

  getCompositeKey(): string {
    return this.teamFeatureOID.toString() + this.scrumTeam.id.toString();
  }
}
linter说它能识别这个功能,但浏览器不能。 错误类型错误:ptf.getCompositeKey不是函数

你能解释一下为什么以及如何使函数可见吗?到目前为止,我必须将函数放在一个组件中才能使用它。

当您执行ptf:PartialTeamFeature;这只意味着ptf属于PartialTeamFeature类型

为了给ptf赋值,您需要执行以下操作:

let ptf = new PartialTeamFeature();

现在,您应该能够访问ptf上可用的对象/方法了

ptf是如何定义的?我在组件ptf:PartialTeamFeature中定义了它;它被映射到subscribe方法中。当我登录到控制台时,它显示所有的ptf属性都存在。它们都不是未定义的或空的。您能发布代码吗?您是否实例化了使用它的类?我的意思是让ptf=新的PartialTeamFeature;是的,看起来Angular subscribe方法将JSON中的属性应用于类,而不是方法。有没有办法使subscribe成为PartialTeamFeature实例,这样我就可以访问实例方法?是的,您可以将返回类型指定为PartialTeamFeature类型,并能够使用实例方法,您能否显示一些代码以及如何订阅它?如果没有细节,很难回答