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);
	}
}

Last updated