我有一个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说它能识别该函数,但浏览器不能。ERROR TypeError: "ptf.getCompositeKey is not a function"
你能解释为什么以及如何使函数可见吗?到目前为止,我必须将函数放在一个组件中才能使用它。
发布于 2019-07-13 00:54:17
当您执行ptf : PartialTeamFeature;
时,这仅仅意味着ptf是PartialTeamFeature
类型。
要为ptf赋值,您需要执行以下操作:
let ptf = new PartialTeamFeature();
现在您应该能够访问ptf上可用的对象/方法了
https://stackoverflow.com/questions/57010685
复制相似问题