restangular icon indicating copy to clipboard operation
restangular copied to clipboard

restangularizeElement with extendModel

Open krmarien opened this issue 11 years ago • 1 comments

Hi,

I have defined some services to get data from a REST API and in those services I use the extendModel function to add extra functions to the received data:

regressionApp.service('ResultService', function (Restangular) {
    Restangular.extendModel('results', function(obj) {
        return angular.extend(obj, {
            aFuncion: function() {
                return "a value";
            }
        });
    });
    return {
        getResults: function () {
            return Restangular.all('results');
        }
    }
});

But now I have one such result embedded in another restangular model, this result is raw json. So I want to convert it to the restangular object with the function aFunction. To convert I tried Restangular.restangularizeElement(null, jsonObject, 'results'), after calling this function I get a restangular object, but the function defined in extendModel cannot be called.

How can I convert the json to the correct restangular object?

Thank you,

krmarien avatar Mar 04 '15 07:03 krmarien

The extendModel was in an external service that was not loaded.

krmarien avatar Mar 07 '15 16:03 krmarien