getting started
- First, install ngx-warehouse via npm or yarn.
- Next, import the NgxWarehouseModule in your AppModule.
- Finally, add the NgxWarehouseModule to your AppModule imports.
$ npm install --save ngx-warehouse
or
$ yarn add ngx-warehouse
import { NgxWarehouseModule } from 'ngx-warehouse';
@NgModule({
declarations: [...],
imports: [
...
NgxWarehouseModule,
...
],
bootstrap: [...]
})
ngx-warehouse comes with a default configuration to get up and running quickly. However, if you'd like to customize the options, it's easy to do so.
import { NgxWarehouseModule, WarehouseConfig, DRIVER_TYPE } from 'ngx-warehouse';
const config: WarehouseConfig = {
driver: DRIVER_TYPE.DEFAULT,
name: 'Your App',
version: 1.0,
storeName: 'key_value_pairs', // Should be alphanumeric, with underscores.
description: 'A description of your app'
};
@NgModule({
declarations: [...],
imports: [
...
NgxWarehouseModule.configureWarehouse(config),
...
],
bootstrap: [...]
})
Now you're ready to use ngx-warehouse in your app.
import { Warehouse } from 'ngx-warehouse';
@Component({
...
})
export class MyComponent implements OnInit {
constructor(public warehouse: Warehouse) { }
ngOnInit() {
this.warehouse.get('key').subscribe(
data => console.log(data),
error => console.log(error)
);
}
}
Saves an item to the current offline data store. The following data types are valid:
Warehouse.set('key', value).subscribe(
(item) => {
// do something with newly saved item
},
(error) => {
// handle the error
}
);