/* let's find a single resource of type `Article` and id `1` */
let query = {
type: 'Article',
id: '1',
}
// to fetch this 'article' from the server:
let queryResults = this.ngrxService.findOne({query: query});
No requests will be sent to the server, the resource will be fetched from the state (if found!). Default is server side fetching.
let query = {
type: 'Article',
id: '1',
}
let queryResults = this.ngrxService.findOne({query: query, fromServer: false});
/* let's find all resources of type `Article` */
let query = {
type: 'Article',
}
// to fetch all articles from the server:
let queryResults = this.ngrxService.findMany({query: query});
// to do the same thing without sending requests to the server:
let queryResults = this.ngrxService.findMany({query, fromServer: false});
The toRemote
parameter which is set to true
in all the examples below makes an immediate request to the server. The other approach is explained in advanced usage.
let resource = {
type: 'Article',
id: '1',
attributes: {
title: 'Randomness'
}
};
// create a resource by sending a POST request immediately
this.ngrxService.postResource({resource: resource, toRemote: true})
let resource = {
type: 'Article',
id: '1',
attributes: {
title: 'Randomness'
}
};
this.ngrxService.patchResource({resource: resource,
toRemote: true})
this.ngrxService.deleteResource({resourceId: {type: 'Article', id: '10'}, toRemote: true})