javascript 离子HTTP GET

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了javascript 离子HTTP GET相关的知识,希望对你有一定的参考价值。

import { HttpClient } from '@angular/common/http';
import { Injectable } from '@angular/core';

/*
  Generated class for the PokedexProvider provider.

  See https://angular.io/guide/dependency-injection for more info on providers
  and Angular DI.
*/
@Injectable()
export class AppService {

  constructor(public http: HttpClient) {
    
  }

  getBooks()
  {
    return this.http.get('http://booksapi.co/api/v2/book/2');
  }

}
title: any = 'List of books are represted in the bookstore';
  books: any = []; 
  constructor(private service:  AppService){
  }

  ngOnInit(){
    this.getBookDetails();
  }

  getBookDetails() {
    this.service.getBooks().subscribe(books => {
      this.books = books.json();
      console.log(this.books);
    });
  }

以上是关于javascript 离子HTTP GET的主要内容,如果未能解决你的问题,请参考以下文章