Skip to content

Adding functionality to resources #54

Closed
@kentcdodds

Description

@kentcdodds

I have a user resource and I want to add functionality to it to make things easier to work with. For example, with ngResource I did something like this:

var User = $resource(BaseUrl + '/api/v1/rest/users/:id', { id: '@_id' });
User.prototype.getDisplayName = function() {
  if (this.name.first && this.name.last) {
    return (this.name.first || '') + ' ' + (this.name.last || '');
  } else if (this.username) {
    return '@' + this.username;
  } else {
    return 'Anonymous';
  }
};

So, with the direction that angular-data is going, would you recommend:

  1. Have a UserControllerService or something that would act on the POJO
  2. Hook the lifecycle of the resource (like afterCreate) and return a new User(data) version of the POJO?

Looking forward to using this and hopefully providing good feedback and PRs 👍

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions