service-contactlist-rxjs.service.ts 874 Bytes
Newer Older
Ooh-Ao committed
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36
import { Injectable } from '@angular/core';
import { from, Observable } from 'rxjs';
import { ContactLists } from './contact-list';
import { ContactList } from './contact-list-data';


@Injectable({
  providedIn: 'root'
})
export class ServiceContactlistRxjsService {

  constructor() { }

  private contactList: ContactLists[] = ContactList;


  // getContactList(): Observable<ContactLists> {
  // You can also fetch data from Api using HttpClient.
  //   return this.http.get(url..)
  // }
  getContactList(): Observable<ContactLists> {
    return from(this.contactList);
  }

  deleteContactList(id: number): void {
    this.contactList = this.contactList.filter(cl => cl.Id !== id);
  }

  addContactList(cl: ContactLists): void {
    this.contactList?.push(cl);
  }

  updateContactList(index: number, cl: ContactLists): void {
    this.contactList[index] = cl;
  }
}