Use a collection

This page will show you how to import and use a collection.

Once you have declared collections and models to your plugin, you can use them in your view-models, or anywhere else you can use aurelia dynamic injector.

1. In your view-model

Aurelia-collection provide a custom resolver called UseCollection to simply inject your different collections :

import { inject } from 'aurelia-framework';
import { UseCollection } from 'aurelia-collection';

@inject(UseCollection.of('Some'))
export class MyClass {
  constructor(someCollection) {
    this.someCollection = someCollection;
  }

  activate() {
    return this.someCollection.get('modelUniqueID')
      .then(model => {
        // do something with your model.
      })
      .catch(console.error);
  }

🚧

Note that model will be either a plain object literal or a model class instance depending of how you declared this collection.


What’s Next

Implement your own collection & model