SapphireDb logo SapphireDb

Get started - Setup angular client

ng-sapphiredb is a client implementation for Angular.

Installation

Install package

To install the package execute the following command in your console

You can find the project here: https://www.npmjs.com/package/ng-sapphiredb

Import SapphireDbModule

Import the module in your app.module.ts

\f:(typescript:app.module.ts) @NgModule({\n \timports: [\n \t\tSapphireDbModule\n \t],\n \tproviders: [\n \t\t{\n \t\t\tprovide: SAPPHIRE_DB_OPTIONS,\n \t\t\tuseValue: {\n \t\t\t\tserverBaseUrl: environment.serverBaseUrl,\n \t\t\t\tapiSecret: 'pw1234',\n \t\t\t\tapiKey: 'webapp',\n \t\t\t\tconnectionType: 'websocket'\n \t\t\t}\n \t\t}\n \t],\n })\n export class AppModule {}
SAPPHIRE_DB_OPTIONS is optional. ng-sapphiredb will automatically get the current url, port and protocol and call the correct endpoint.
ng-sapphiredb will also figure out a working connection type for your client.

Access the database

To call function on the database you have to inject SapphireDbService in your components etc.

\f:(typescript:main.component.ts) constructor(private db: SapphireDbServiceService) { }
Make sure to import SapphireDb from ng-sapphiredb and not from sapphiredb

Browser compatibility

BrowserWebsocketSSEPolling
Chrome
Firefox
Opera
Edge
Internet Explorer 11

Example

You can also check out the example project: Example

Done

Your SapphireDb-client should now work.

Start using it by querying data

This website uses Google Analytics. If you want to disable it just unselect the option: