@obelisk/ngx
A client library Angular Module written in Typescript to interact with @obelisk/client.
Prerequisites
This library makes use of:
- RxJS (Reactive Extensions for JavaScript). RxJS comes as a peer dependency.
- @obelisk/client
Installation
npm install @obelisk/client @obelisk/ngx rxjs --save
Usage
To include it in you main AppModule, do this:
import { APP_INITIALIZER } from '@angular/core';
import { ClientOptions } from '@obelisk/client';
import { ObeliskNgxModule, ObeliskService, OBELISK_DEPS, factory } from '@obelisk/ngx';
const options: ClientOptions = {
host: 'https://obelisk.ilabt.imec.be',
apiVersion: 'v1',
realm: 'idlab-iot',
clientId: 'my-client'
}
@NgModule({
declarations: [...],
imports: [
...,
ObeliskNgxModule.forRoot(options)
],
providers: [
{
provide: APP_INITIALIZER,
deps: OBELISK_DEPS,
useFactory: factory,
multi: true
}
...
],
bootstrap: [AppComponent]
})
export class AppModule { }
Now you can inject ObeliskService and get an already initialized client from it any time.
If you are logged in it will handle all the tokens in the headers for you.
Configure via URL
If instead of an object, you feed ObeliskNgxModule.forRoot()
a string, then it will interpret it as a URL and fetch the configuration object asynchronously from that url first.