Skip to content

Ease collection handling #2

@astik

Description

@astik

I have a factory :

module.factory('siteService', function($q, $log, JsonldRest) {
    var api = {};

    JsonldRest.setBaseUrl('/api/v1/');
    var entitiesHandler = JsonldRest.collection('sites');

    api.findAll = function() {
        $log.log('siteService.findAll');
        return entitiesHandler.getList();
    };

    return api;
});

While using the findAll function, I get this error :

Error: Response for getList SHOULD be an array and not an object or something else

This is completely normal as the JSON is like :

{
  "@context":"/contexts/Site",
  "@id":"/sites",
  "@type":"hydra:PagedCollection",
  "hydra:totalItems":14,
  "hydra:itemsPerPage":30,
  "hydra:firstPage":"\/sites",
  "hydra:lastPage":"\/sites",
  "hydra:member":[
   {"@id":"/sites/1","@type":"Site","lang":"es"},
   {"@id":"/sites/2","@type":"Site","lang":"en"}
  ]
}

It is clear I need to work with "hydra:member". But I'd really like a simple way to manipulate the list.

@dunglas has a sweet approach to that :
https://github.com/dunglas/DunglasJsonLdApiBundle#angularjs-integration

What I like is that we can manipulate directly the list (this is what is recommended by mgonto in its demo slide), but, in addition to that, we keep the pagination meta data.

I would be great to have this add-on directly into angular-jsonld in idea to have less code to bootstrap (I know, I'm lazy =P)

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions