Open uberspeck opened 9 years ago
+1
+1
To be more concrete, in my case I have the following issue:
I register the api like this:
api = registerApi('/foo/bar/', function(model)
{
model.getDropDownId = function() { return this['@id']; };
model.getDropDownValue = function() { return this.title; };
return model;
});
The later when I call this, everything works:
api.getList().then(function(data)
{
console.log(data[0].getDropDownValue());
// Returns: test
});
But if I call this in the same context I am getting a TypeError: data.getDropDownValue is not a function
:
api.one(1).get().then(function(data)
{
console.log(data.getDropDownValue());
});
... and as I wrote this comment, I figured out that this is working:
api.get(1).then(function(data)
{
console.log(data.getDropDownValue());
});
+1
I think the problem is when you define your service. Try something like this:
.service("User", function($log, Restangular) {
var User = Restangular.all("users");
Restangular.extendCollection("users", function(obj) {
return angular.extend(obj, {
get: function(id) {
return this.one(id).get();
}
});
});
Restangular.extendModel("users", function(obj) {
return angular.extend(obj, {
talk: function() {
return alert("hi");
}
});
});
return User
}
I'm trying to create a basic data model but methods applied via
extendModel
are not being recognized......then in my controller: