🧠
ngx-crud
  • Introduction
  • API
    • HTTP Operations
    • HTTP Aborting
    • HTTP Caching
    • HTTP Observing
    • HTTP Options
    • HTTP Context
    • HTTP Headers
    • HTTP Params
    • Service Instance
    • Service Options
  • Reference
    • Modules
      • AbortModule
      • CacheModule
      • ObserveModule
      • CrudModule
    • Services
      • AbortService
      • CacheService
      • CommonService
      • CrudService
      • CustomService
      • DeleteService
      • FindService
      • GetService
      • ObserveService
      • PatchService
      • PostService
      • PutService
    • Interceptors
      • AbortInterceptor
      • CacheInterceptor
      • ObserveInterceptor
    • Decorators
      • @ApiUrl
      • @ApiRoute
    • Helpers
      • createUrl
      • createUrlWithId
      • stripUrlParams
  • Examples
    • Services
      • Fully Typed Collection
      • Limited Singleton
    • Components
      • Loader
    • Effects
      • ProfilerEffect
      • ErrorEffect
      • OfflineEffect
  • Links
    • GitHub
Powered by GitBook
On this page
  1. Examples
  2. Services

Limited Singleton

Implementation for a singleton resource that is limited to read and update operations:

import { Injectable, Injector } from '@angular/core';
import { Observable } from 'rxjs';
import
{
	ApiUrl,
	ApiRoute, 
	CommonService,
	CustomService,
	Options,
	OptionsWithBody
} from 'ngx-crud';
import { RequestBody, ResponseBody } from './example.interface';

import { environment } from '@environments';

@Injectable()
@ApiUrl(environment.apiUrl)
@ApiRoute(environment.apiRoutes.example)
export class ExampleService extends CommonService
{
	protected customService : CustomService<RequestBody, ResponseBody> = this.injector.get(CustomService);

	read(options ?: Options) : Observable<ResponseBody>
	{
		return this.customService.bind(this).custom('GET', options);
	}

	update(options ?: OptionsWithBody<ResponseBody>) : Observable<ResponseBody>
	{
		return this.customService.bind(this).custom('PUT', options);
	}
}
PreviousFully Typed CollectionNextComponents

Last updated 3 months ago