fengxiang
2018-07-12 5c0d8040266554b67e852ccb7056c3d0cae4b4ef
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
import { Injectable } from '@angular/core';
import { Observable } from 'rxjs/Observable';
import { catchError } from 'rxjs/operators';
import { _HttpClient } from '@delon/theme';
 
@Injectable()
export class RandomUserService {
    randomUserUrl = 'https://api.randomuser.me/';
 
    getUsers(PageIndex = 1, pageSize = 10, args?: any) {
        return this.http
            .get(this.randomUserUrl, { results: pageSize, page: PageIndex, _allow_anonymous: true })
            .pipe(catchError(this.handleError));
    }
 
    handleError(error: any) {
        const errMsg = (error.message) ? error.message :
            error.status ? `${error.status} - ${error.statusText}` : 'Server error';
        console.error(errMsg); // log to console instead
        return Observable.throw(errMsg);
    }
 
    constructor(private http: _HttpClient) {
    }
 
 
}