Axios和Angular
试图找出如何在Angular cli,基础脚手架中进行axios导入和使用.
我没有找到任何文件. 我找到了这个 他的建议并不适用. Cli在添加任何代码位时中断. 有关如何在Angular中进行基本的后api调用的任何见解? 我得到的最好的是(有角度的原生方法): import { Component } from '@angular/core'; import { Injectable } from '@angular/core'; import { Http } from '@angular/http'; @Component({ selector: 'app-root',templateUrl: './app.component.html',styleUrls: ['./app.component.css'] }) @Injectable() export class AppComponent{ title = 'prouuuut'; posts = []; errors = []; constructor(private http: Http){ } fetchAll(){ this.http.get('https://api.github.com/repositories') .then(response => { this.posts = response.data.entry }) .catch(e => { this.errors.push(e) }) } } 在app.component.ts里面,但我已经有: 解决方法
最有可能使用Axios的具体类而不是Angular的Http具体类不是一种有效的方法,因为每个类都有不同的接口.
你需要 > npm install @ types / axios 请注意,建议使用Angular的Http客户端模块 来自axios github页面:
Angular’s(Angular 2)Http客户端比Angular JS的Http客户端更强大,所以我做不到想一想要求你进行这种转换的原因 (编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |