Advertisement
hersy91

Untitled

Nov 16th, 2019
303
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. import { Injectable } from '@angular/core';
  2. import { HttpClient } from '@angular/common/http';
  3. import { Dati } from './dati';
  4. import {HttpHeaders} from '@angular/common/http'
  5.  
  6. @Injectable({
  7.   providedIn: 'root'
  8. })
  9. export class RestAPIService {
  10.  
  11.   constructor(private http:HttpClient){}
  12.  
  13.   dati:Dati[] = new Array();
  14.  
  15.  
  16.   testing(){
  17.     //SE VOGLIO USARE UN TOKEN LO METTO QUA
  18.     const httpOp = {
  19.       headers: new HttpHeaders({
  20.       'Authorization' : 'token'
  21.     })}
  22.     //RICHIAMO UN API
  23.     this.http.get<Dati[]>("https://antares.hersel.it/testapi.php")
  24.       .subscribe((resp:Dati[])=>{
  25.         resp.forEach((x)=>this.dati.push(x))
  26.         console.log(this.dati)
  27.       })
  28.  
  29.   }
  30.   getDati(){
  31.     return this.dati
  32.   }
  33. }
  34.  
  35.  
  36. //const httpOptions = {
  37.   //headers: new HttpHeaders({
  38.  
  39.     //'Content-Type': 'application/json',
  40.     //'Authorization': 'token'
  41.   //})
  42. //}
  43. //httpOptions.headers.set('Authorization','token')
  44. //this.http.get<data_type>(this.url,httpOptions)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement