I have a problem (sorry about my english). In my Angular 4 application with TypeScript, i use a get() method and a subscribe() method to receive a remote object in JSON format and deserialize it to get an instance of a class that matches perfectly with my JSON data (all class data fields are mirrored in the json file).
It seems that everything works, because I can normally use these object data fields in my HTML template (the object is actually created and instantiated).
the problem (that I don't explain) occurs when I insert in this class new methods or new data fields. The HTML template doesn't display these new data fields or the result of new methods, and I do not explain why this happens.
How can I solve this problem? 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);
});
At this point if I tried to create a method in ExampleObject:
export class ExampleObject {
property1: string;
property2: string;
getHello() {
return 'Hello';
}
}
In the HTML template the following instructions works
{{exampleObject.property1}}
{{exampleObject.property2}}
But this instruction doesn't work:
{{exampleObject.getHello()}}