import { Injectable } from '@angular/core' ; import { BehaviorSubject } from 'rxjs' ; import { Issue } from '../models/issue' ; import { HttpClient , HttpErrorResponse } from '@angular/common/http' ; @ Injectable ( ) export class DataService { private readonly API_URL = 'https://api.github.com/repos/angular/angular/issues' ; dataChange : BehaviorSubject < Issue [ ] > = new BehaviorSubject < Issue [ ] > ( [ ] ) ; dialogData : any ; constructor ( private httpClient ) { } get data ( ) : Issue [ ] { return this . dataChange . value ; } getDialogData ( ) { return this . dialogData ; } /** CRUD METHODS */ getAllIssues ( ) { this . httpClient . get < Issue [ ] > ( this . API_URL ) . subscribe ( data => { this . dataChange . next ( data ) ; } , ( error ) => { console . log ( error . name + ' ' + error . message ) ; } ) ; } addIssue ( issue ) { this . dialogData = issue ; } updateIssue ( issue ) { this . dialogData = issue ; } deleteIssue ( id ) { console . log ( id ) ; } }