I'm currently tackling a situation while working with Angular. Here's the scenario:
The my.service.ts contains the following class:
export class MyClass {
MyList: string[] = [];
MyString: string = '';
createString(): void {
this.MyList.forEach(s => {
this.MyString += s + ', ';
});
}
}
And in my.component.ts, it is being utilized like this:
myData: MyClass[] = [];
this.myService.getMyData().subscribe(res => {
myData = res;
if (myData.length > 0) {
this.myData.forEach(x => x.createString());
}
});
Even though VS Code recognizes the createString
function as a method of MyClass
, an error persists:
ERROR TypeError: x.createString is not a function
Any insights into why this might be happening?
EDIT: The data originates from the backend, and the model on the backend lacks this method. Could that be causing the issue?