You need to sign in or sign up before continuing.
contact.service.ts 858 Bytes
Newer Older
1
import { HttpClient } from '@angular/common/http';
2
import { Injectable } from '@angular/core';
Your Name committed
3
import { Observable } from 'rxjs';
4
import { Contact } from "../models/contact.model";
5 6 7

@Injectable({ providedIn: 'root' })
export class ContactService {
8 9

    constructor(private http: HttpClient) { }
Your Name committed
10 11
    url: string = "http://915e-49-0-64-28.ngrok.io";
    listContact: Contact[] = []
12

13 14
    addContact(model: Contact) {
        this.listContact.push(model);
15
        this.listContact.reverse
16
    }
17

Chanachai committed
18 19 20 21 22 23 24 25 26
    updateContact(row_obj: Contact) {
        this.listContact = this.listContact.filter((value, key) => {
            if (value.id === row_obj.id) {
                value = row_obj;
            }
            return true;
        });
    }

Your Name committed
27 28
    getListContact(): Observable<Contact[]> {
        return this.http.get<Contact[]>(this.url + "/contact/lists");
29 30 31
    }
}