mgonto / restangular

AngularJS service to handle Rest API Restful Resources properly and easily
MIT License
7.88k stars 843 forks source link

Add ability to get a lazy plain object. #1025

Open DylanPiercey opened 9 years ago

DylanPiercey commented 9 years ago

It's really useful that I am able to get an object reference from Restangular and have angular update the view dynamically.

<div ng-init="Restangular.all('example').getList().$object">
// Do stuff with restangular on the result.

However it would be nice to have access to both a restangular document and a non-restangular document.

<div ng-init="Restangular.all('example').getList().$plain">
// Do stuff without restangular.

Is this possible now?

TimDaub commented 9 years ago

Do you mean an object that is equal to the one on your server? One without any Restangular-specific properties?

That is actually possible. Look here: https://github.com/mgonto/restangular#element-methods

plain()

DylanPiercey commented 9 years ago

The problem is that I can't use #plain in the view because it is only attached after the response.

grabbou commented 9 years ago

The best way to make that happen for now is probably to define $scope.allRecords that you gonna use in the template and then, once promise is resolved, assigning plain() to allRecords manually. Please let me know if that works for you. In v2 this will be considered as a feature.