UNPKG

@experteam-mx/ngx-services

Version:

Angular common services for Experteam apps

81 lines (60 loc) 1.78 kB
# @experteam-mx/ngx-services Common Angular services used across Experteam applications. ## Standalone setup (Angular v20+) Use `provideNgxServices(environment)` in your `ApplicationConfig.providers`. ```ts import { provideHttpClient, withInterceptors } from '@angular/common/http' import type { ApplicationConfig } from '@angular/core' import { provideRouter } from '@angular/router' import { apiHeadersInterceptor, apiTokenInterceptor, httpCachingInterceptor, provideNgxServices, type Environment } from '@experteam-mx/ngx-services' import { environment } from '../environments/environment' import { routes } from './app.routes' const envs = { ...environment, authCookie: 'token', cacheTtl: 3000 } as Environment export const appConfig: ApplicationConfig = { providers: [ provideRouter(routes), provideNgxServices(envs), provideHttpClient(withInterceptors([ apiHeadersInterceptor, apiTokenInterceptor, httpCachingInterceptor ])) ] } ``` `provideNgxServices` registers `ENVIRONMENT_TOKEN`, which is required by the API services and some interceptors in this package. ## NgModule compatibility `NgxServicesModule.forRoot(environment)` is still available for compatibility, but it is deprecated for new standalone applications and will be removed in `20.2.0`. ```ts import { importProvidersFrom } from '@angular/core' import { NgxServicesModule } from '@experteam-mx/ngx-services' providers: [ importProvidersFrom([NgxServicesModule.forRoot(envs)]) ] ``` Prefer `provideNgxServices(envs)` for all new apps. ## Build ```bash ng build @experteam-mx/ngx-services ``` Build output: `dist/experteam-mx/ngx-services` ## Publish ```bash cd dist/experteam-mx/ngx-services npm publish ``` ## Test ```bash ng test @experteam-mx/ngx-services ```