forked from PatrickJS/PatrickJS-starter
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtab.services.ts
28 lines (23 loc) · 819 Bytes
/
tab.services.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
import { Injectable } from '@angular/core';
import { Http ,Response } from '@angular/http';
import { TABITEM } from './tab.interface';
import { Observable } from 'rxjs/Observable';
@Injectable()
export class TabServices {
private url = '/assets/data.json';
constructor(private http: Http) {}
getData(): Observable<TABITEM[]> {
return this.http.get(this.url)
.map(this.extractData)
// .catch(this.handleError);
}
private extractData(res: Response) {
return res.json() || { };
}
private handleError(error: any){
let errMsg = (error.message) ? error.message :
error.status ? `${error.status} - ${error.statusText}` : 'Server error';
console.error(errMsg); // log to console instead
return Observable.throw(errMsg);
}
}