-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathnavigation.service.ts
47 lines (35 loc) · 1.17 KB
/
navigation.service.ts
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
37
38
39
40
41
42
43
44
45
46
47
import { HttpClient, HttpErrorResponse } from '@angular/common/http';
import { Injectable } from '@angular/core';
import { BehaviorSubject } from 'rxjs';
@Injectable({
providedIn: 'root'
})
export class NavigationService {
private title: BehaviorSubject<string> = new BehaviorSubject("");
public title$ = this.title.asObservable();
private loading: BehaviorSubject<boolean> = new BehaviorSubject(false);
public loading$ = this.loading.asObservable();
private sending: BehaviorSubject<boolean> = new BehaviorSubject(false);
public sending$ = this.sending.asObservable();
private _error: BehaviorSubject<string | null> = new BehaviorSubject<string | null>(null);
public error$ = this._error.asObservable();
constructor(
private http: HttpClient,
) {}
setTitle(title: string) {
this.title.next(title);
}
setLoading(state: boolean) {
this.loading.next(state);
}
setSending(state: boolean) {
this.sending.next(state);
}
error(e: HttpErrorResponse) {
this._error.next(`Response: ${e.status} ${e.statusText}\nEndpoint: ${e.url}`);
}
deletePost(id: number) {
console.log(id) // test
return this.http.delete("" + id)
}
}