Is there a trick to send the Model attribute functions over Http gets ?
so assuming i have a model User :
attributes: {
last_name : "string" ,
first_name: "string",
name : function()
{
return this.first_name + " " + this.last_name;
}
}
Controller :
User.findOne( { id : 1}).exec(function(err,user) {
res.view("profile", {user:user});
});
and a view :
<div>
<h4> hi <%= user.name() %>
</div>
everything works perfectly.
however if I am loading the data through a client : Controller :
User.findOne( { id : 1}).exec(function(err,user) {
res.json({user:user}); // or res.send({user: user});
});
and in Client (Angular):
$http.get("/controller/method/").then(function(data){
$scope.user = data;
});
the view cannot do that anymore as easy as it used to :
<div>
<h4> hi {{ user.name() }} </h4>
</div>
Any ideas or workarounds ? I tried overwriting the toJSON method of the model but no luck. would appreciate any ideas here.