-
Notifications
You must be signed in to change notification settings - Fork 1
Home
Mihael Safaric edited this page Apr 3, 2019
·
5 revisions
ngx-hal is a data store with a support for handling HAL formatted HTTP requests.
npm install --save ngx-hal
After the initial ngx-hal setup (see Getting started section) you have to create a resource model which extends HalModel
from the ngx-hal
and a resource service which extends ModelService
from ngx-hal
.
The following example uses User
resource as an example.
user.model.ts
class User extends HalModel {
@Attribute()
public name: string;
}
user.service.ts
class UserService extends ModelService<User> {
constructor(datastore: DatastoreService) {
super(datastore, User);
}
}
And then a few methods are available on an instance of UserService
:
this.userService.findOne('1').subscribe((user: User) => {
console.log('Fetched user', user);
});
this.userService.find().subscribe((users: Array<User>) => {
console.log('Fetched users', users);
});
this.userService.find({}, true).subscribe((halDocument: HalDocument<User>) => {
console.log('Fetched users', halDocument.models);
console.log('Pagination information', halDocument.pagination);
});
- see wiki
ng build
ng test