Hi, I'm using Restangular.
I need to build a model which is built from 3 calls to the api, how can I 
do that?
To get my model ready to show, I need to call the following urls:

api/scores/{id}
api/scores/{id}/voters
api/scores/{id}/witnesses

Also, when I call api/scores it return all the scores, and then for each 
one, I need to call /voters and /witnesses.

I thought of creating a javascript class ScoreModel which would have all 
the score properties along with the voters and witnesses, then bind the 
ScoreModel array to $scope. But how to coordinate the Restangular calls to 
build the model?

I drafted something, but it's just plain ugly!

scoreApp.factory('Scores', ['Restangular', function (Restangular) {
    return Restangular.service('scores');
}]);

var promise = Scores.getList({ timeUp: false });
    $scope.promise = promise;
    promise.then(function (scores) {
        //$scope.scores = scores;
        var promises = [];
        scores.forEach(function (score) {
            promises.push(score.getList('voters'));
        });
        $scope.promise = promises;
        promises.forEach(function (promise) {
            promise.then(function (voters) {

            });
        });
    }, function (data) {
        toaster.pop('error', '', 'Sorry, but an error occured');
    });

-- 
You received this message because you are subscribed to the Google Groups 
"AngularJS" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To post to this group, send email to [email protected].
Visit this group at http://groups.google.com/group/angular.
For more options, visit https://groups.google.com/d/optout.

Reply via email to