首页
学习
活动
专区
圈层
工具
发布
首页
学习
活动
专区
圈层
工具
MCP广场
社区首页 >问答首页 >Angular 8: ERROR TypeError:“Angular is not a TypeError”

Angular 8: ERROR TypeError:“Angular is not a TypeError”
EN

Stack Overflow用户
提问于 2019-07-13 00:18:40
回答 1查看 27关注 0票数 0

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

代码语言:javascript
运行
复制
ptf.getCompositeKey()

我已经尝试将其更改为静态方法。

代码语言:javascript
运行
复制
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说它能识别该函数,但浏览器不能。ERROR TypeError: "ptf.getCompositeKey is not a function"

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

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2019-07-13 00:54:17

当您执行ptf : PartialTeamFeature;时,这仅仅意味着ptf是PartialTeamFeature类型。

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

代码语言:javascript
运行
复制
let ptf = new PartialTeamFeature();

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

票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/57010685

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档