@experteam-mx/ngx-services
Common Angular services used across Experteam applications.
Standalone setup (Angular v20+)
Use provideNgxServices(environment) in your ApplicationConfig.providers.
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'
// cacheRoutes is opt-in; omit or leave empty until routes are registered:
// cacheRoutes: [
// { pattern: '/api/catalogs', ttl: 60_000 },
// { pattern: '/api/companies/.+/branches', ttl: 30_000 }
// ]
} 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.
httpCachingInterceptor caches only GET requests whose URL matches an entry in cacheRoutes (first matching RegExp pattern wins). With no routes configured, nothing is cached.
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.
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
ng build @experteam-mx/ngx-services
Build output:
dist/experteam-mx/ngx-services
Publish
cd dist/experteam-mx/ngx-services
npm publish
Test
ng test @experteam-mx/ngx-services