I'm facing an issue in my Angular 4 application with TypeScript. I am using a get() method and a subscribe() method to receive a remote object in JSON format and deserialize it to match a class structure. When all the class data fields are mirrored in the JSON file, everything seems to work fine as I can access and use these object data fields in my HTML template.
However, when I try to add new methods or data fields to this class, the HTML template does not display these new additions. I am unable to understand why this is happening and how to solve this problem.
Here's an example:
// In ExampleObject.ts
export class ExampleObject {
property1: string;
property2: string;
}
// In another file
exampleObject: ExampleObject;
getCurrentObject() {
this.objectService.getObjcet().subscribe(
data => this.exampleObject = data,
error => {
console.log('some error found: ' + error);
});
If I try to add a method in ExampleObject like this:
export class ExampleObject {
property1: string;
property2: string;
getHello() {
return 'Hello';
}
}
The following instructions in the HTML template work:
{{exampleObject.property1}}
{{exampleObject.property2}}
But this instruction does not work:
{{exampleObject.getHello()}}