I'm working on a service as a model in AngulaJS. I use a factory nad I want to use the angular.extend() thing to add attributes/properties to the $resource object.
The problem is that I can't access attributes added with this :
var myObject = $resource(...);
angular.extend(myObject.prototype, {
hi : "hi",
findFriend : function(){ console.log("You are all alone...") }
}
I'm not able to access "hi" or "findFriend" in my controller nor in the factory with a console.log().
But if I do this :
var myObject = $resource(...);
angular.extend(myObject, {
hi : "hi",
findFriend : function(){console.log("It works"}
}
Then I'm able to access those attributes. If the good practice is the second one, then what is the difference with :
var myObject = $resource(...);
myObject.hi = "hi";
myObject.findFriend("It works");
?
I read the documentation and followed this article to build my model.
Can someone explain why one work and not the other ? Why it seems to be different from the article ?
Thank you :)