I am building a sample project with Angular2/Typescript in order to use it as a new frontend for an existing backend code.
I really like the ability to create types and consider to use some of the JSON objects served by the backend as typed classes like this:
module DomainObjects {
export class SomeDomainObject {
constructor(attr1:string, attr2:number) {...}
...
}
}
Some of the JSON code that is returned by the backend is very large, so I don't want to work with a huge amount of parameters in the constructor. At best i just pass a JSON object as a single parameter to the constructor which does some checks (or not). On the other hand I'd like to access the JSON object directly. Is something like this possible:
myobject:SomeDomainObject;
...
this.myobject = new SomeDomainObject({id:10,color:'green'});
and access myobject in a template like this
{{myobject.color}}
without having another reference like {{myobject.json.color}}