If I have some property in a service that I want to set equal to the data I get back from a network call, I can do something like this:
//SERVICE//
thisService.property = data;
//SERVICE//
and in my controller I can do:
//CONTROLLER//
this.property = ThisService.property;
//CONTROLLER//
so that I can bind to it in the HTML and have it dynamically update:
//VIEW//
{{property}}
//VIEW//
However, as you may know, this does not work. The controller.property remains undefined, as this line:
thisService.property = data;
will create a new reference for thisService.property, and the old one, set in the controller, will not point to the new data.
So, what I have to do is wrap the data in another object, and do something like this:
//SERVICE//
thisService.property = {};
thisService.property.property = data;
//SERVICE//
//CONTROLLER//
this.property = ThisService.property;
//CONTROLLER
//VIEW//
{{property.property}}
//VIEW//
This is rather crude and ugly. Is there a better, cleaner way of achieving this?