So I have this class inside this class object I instance it, but I can’t call its functions. The IDE allows me to call the getPoistionDiagram:
export class NodeW {
childrenIds: string[];
diagram?: {
coordinates: {
x: number;
y: number;
};
} | null;
nodeId: string;
parameters: {
childrens?: string[];
name?: string;
nodeNumber?: string;
original?: string;
cases?: any;
parent?: any;
extra?: any;
copyIds?: any;
copyNames?: any;
};
type: NodeType;
constructor(
childrenIds: string[],
nodeId: string,
parameters: {},
type: NodeType,
diagram?: { coordinates: { x: number; y: number } },
) {
this.childrenIds = childrenIds;
this.diagram = diagram;
this.nodeId = nodeId;
this.parameters = parameters;
this.type = type;
}
getPositionDiagram(i: number): { x: number; y: number } {
return {
x: !this.diagram ? 20 * 10 : this.diagram.coordinates.x,
y: !this.diagram ? i * 120 : this.diagram.coordinates.y,
};
}
}
export class NodesArray {
private nodes: NodeW[];
private createNewNodesService?: CreateNewNodesService;
constructor(nodes?: NodeW[]) {
if (nodes && nodes.length > 0) {
this.nodes = nodes;
} else {
this.nodes = DEFAULT_NODE_ARRAY();
}
}
getNodes(): NodeW[] {
return this.nodes;
}
setNodes(nodes: any) {
this.nodes = nodes;
}
getParentNode(nodeId: string) {
for (let i = 0; i < this.nodes.length; i++) {
if (this.nodes[i].childrenIds.includes(nodeId)) {
return this.nodes[i].nodeId;
}
}
return null;
}
}
So when I do:
this.nodes?.getNodes()!.forEach((node: NodeW, i) => {
node.getPositionDiagram(i) // => .getPoistonDiagram() is not a function
});
Trying to use the method inside the attribute that i have. It doesn’t allow me to acces to the method of the NodeW, also it says is not a typeOf NodeW when i check it.
Is it something related to the froEach()?
New contributor
Marc Puerto is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.