JSPM

ng-base-service

0.0.6
  • ESM via JSPM
  • ES Module Entrypoint
  • Export Map
  • Keywords
  • License
  • Repository URL
  • TypeScript Types
  • README
  • Created
  • Published
  • 0
  • Score
    100M100P100Q27579F
  • License MIT

BaseService is a service for angular API CRUD

Package Exports

  • ng-base-service

This package does not declare an exports field, so the exports above have been automatically detected and optimized by JSPM instead. If any package subpath is missing, it is recommended to post an issue to the original package (ng-base-service) to support the "exports" field. If that is not possible, create a JSPM override to customize the exports field for this package.

Readme

NG BASE SERVICE

BaseService is a service for angular API CRUD

Installation

npm i ng-base-service

This command automatically installs the necessary files, as well as stores ng-base-service as a dependency in your project's package.json file.

Configuration

There is no additional configuration needed!

API

Method Description
getById(id: any) This method get items by id
getAll() This method get all items
add(context: TEntity) This method add or create new items
update(id: any, context: TEntity) This method edit or update existin item
delete(id: any) This method delete existin item

Usage

You need to extends class BaseService<TEntity> or BaseAsyncService<TEntity> in your class service.ts

Import BaseService

//......
import { BaseService } from "ng-base-service";
//......

@Injectable({ providedIn: "root" })
export class TestService extends BaseService<Test> {
  constructor(http: HttpClient) {
    super(http, "endPointURL");
  }
}
  constructor( private _testService: TestService ) {}

  getById() {
    this._testService.getById(1).subscribe(res => console.log(res));
  }

  getAll() {
    this._testService.getAll().subscribe(res => console.log(res));
  }

  create(context: any) {
    this._testService.add(context).subscribe(res => console.log(res));
  }

  edit(id: any, context: any) {
    this._testService.update(id, context).subscribe(res => console.log(res));
  }

  delete(id: any) {
    this._testService.delete(id).subscribe(res => console.log(res));
  }

Import BaseAsyncService

//......
import { BaseAsyncService } from "ng-base-service";
//......

@Injectable({ providedIn: "root" })
export class TestService extends BaseAsyncService<Test> {
  constructor(http: HttpClient) {
    super(http, "todos");
  }
}
  constructor(private _testService: TestService) {}

  getById() {
    this._testService.getById(1).then(res => console.log(res));
  }

  getAll() {
    this._testService.getAll().then(res => console.log(res));
  }

  create(context: any) {
    this._testService.add(context).then(res => console.log(res));
  }

  edit(id: any, context: any) {
    this._testService.update(id, context).then(res => console.log(res));
  }

  delete(id: any) {
    this._testService.delete(id).then(res => console.log(res));
  }