Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import { Injectable } from '@angular/core';
- import { Http, Response } from '@angular/http';
- import { Observable } from 'rxjs/Observable';
- import 'rxjs/add/operator/catch';
- import 'rxjs/add/operator/map';
- /*
- Generated class for the RestApiProvider provider.
- See https://angular.io/docs/ts/latest/guide/dependency-injection.html
- for more info on providers and Angular DI.
- */
- @Injectable()
- export class RestApiProvider {
- private apiUrl = 'http://127.0.0.1:8080/Datasnap/Rest/TServerMethods1/RequestOrderProduct';
- public Dados: any
- constructor(public http: Http) {
- console.log('Hello RestApiProvider Provider');
- this.ResultTeste;
- }
- getprodutos(): Observable<string[]> {
- return this.http.get(this.apiUrl)
- .map(this.extractData)
- .catch(this.handleError);
- }
- private extractData(res: Response) {
- let body = res.json();
- return body || { };
- }
- ResultTeste() {
- this.Dados = this.getprodutos();
- console.log('Teste '+ this.Dados);
- }
- private handleError (error: Response | any) {
- let errMsg: string;
- if (error instanceof Response) {
- const body = error.json() || '';
- const err = body.error || JSON.stringify(body);
- errMsg = `${error.status} - ${error.statusText || ''} ${err}`;
- } else {
- errMsg = error.message ? error.message : error.toString();
- }
- console.error(errMsg);
- return Observable.throw(errMsg);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement