Skip to content

Getting started

Mihael Šafarić edited this page Feb 19, 2019 · 3 revisions

Datastore service needs to be provided somewhere in the application. Usually, that is your top-most module.

import { NgModule } from '@angular/core';
import { DatastoreService } from 'ngx-hal';

@NgModule({
  declarations: [...],
  imports: [...],
  providers: [
    {
      provide: DatastoreService,
      useClass: HalDatastoreService, // your own class which extends DatastoreService
      deps: [
        HttpClient
      ]
    }
  ]
})
export class AppModule { }

TODO Example of HalDatastoreService.

Your models must extends HalModel, example:

Model properties must be decorated with one of the following decorators: Attribute, HasOne, HasMany

example:

import { HalModel } from 'ngx-hal';

export class User extends HalModel {
  @Attribute()
  public name: string;
}

You want to have a dedicated service which will handle all the external operations for the resource. Such service must extends ModelService,

example:

import { Injectable } from '@angular/core';
import { ModelService, DatastoreService } from 'ngx-hal';
import { User } from '../../models/user.model';

@Injectable()
export class UserService extends ModelService<User> {
  constructor(datastore: DatastoreService) {
    super(datastore, User);
  }
}