Main utils to develop site's static data
npm install @ngx-basis/backend-staticYou mast import HttpClientModule in your application before using this lib
#### NPM
``shell`
npm install --save @ngx-basis/backend-static
WARNING: Don't forget to add HttpClientModule.
`js
import { HttpClientModule } from '@angular/common/http';
import { BackendStaticResolver } from '@ngx-basis/backend-static';
@NgModule({
declarations: [AppComponent],
imports: [
HttpClientModule,
RouterModule.forRoot([
{
path: '',
component: AppComponent,
resolve: [BackendStaticResolver],
},
]),
],
})
export class AppModule {}
`
`js
import { HttpClientModule } from '@angular/common/http';
import { BackendStaticResolver, BACKEND_STATIC_DEFAULT_VALUE, BACKEND_STATIC_DEFAULT_VALUE } from '@ngx-basis/backend-static';
@NgModule({
declarations: [AppComponent],
imports: [
HttpClientModule,
RouterModule.forRoot([
{
path: '',
component: AppComponent,
resolve: [BackendStaticResolver],
},
]),
providers: [
{
provide: BACKEND_STATIC_DEFAULT_VALUE,
useValue: 'api url [default "/static"]',
},
{
provide: BACKEND_STATIC_DEFAULT_VALUE,
useValue: {someData: [1, 2, 3]}, // Set this value if responce comes with an error (for debuging if api dosn't exist)
},
],
]
})
export class AppModule {}
`
`js
import { HttpClientModule } from '@angular/common/http';
import { BACKEND_STATIC_CLASS_FOR_INSTANCE } from '@ngx-basis/backend-static';
class Static() {
constructor(data: Static) => {
Object.assign(this, data)
}
}
@NgModule({
declarations: [AppComponent],
...
providers: [
{
provide: BACKEND_STATIC_CLASS_FOR_INSTANCE,
useValue: Static, // raw data from api responce will be curl to this class like Static(data) and will save instance to service
},
],
})
export class AppModule {}
`
`js
import { BackendStaticService } from '@ngx-basis/backend-static';
@Component({
selector: 'core-root',
templateUrl: './app.component.html',
styleUrls: ['./app.component.scss'],
})
export class AppComponent {
get static() {
return this.staticService.static;
}
constructor(private staticService: BackendStaticService) {}
}
``
| Name | Type | Description |
| ------------ | -------------------- | -------------------------------- |
| static$ | BehaveorSubject\
| static | \
| loadStatic() | Observable\