Axios and Angular

前端 未结 1 1299
难免孤独
难免孤独 2021-02-14 09:24

Trying to figure out how to make an axios import and use in an Angular cli, base scaffolding.

I didn\'t find any docs for this.

I found this https://netbasal.c

1条回答
  •  陌清茗
    陌清茗 (楼主)
    2021-02-14 10:05

    Most probably using Axios's concrete class instead of Angular's Http concrete class is not a valid approach since each of these classes would have a different interface.

    You need to

    1. npm install @types/axios
    2. import axios as you import any other third-party library in typescript

    Note that it is recommended to use Angular's Http Client Module

    From axios github page:

    axios is heavily inspired by the $http service provided in Angular. Ultimately axios is an effort to provide a standalone $http-like service for use outside of Angular"

    Angular's (Angular 2+) Http client is more powerful than Angular JS's Http client, so I could not think of a reason that requires you to be making this switch

    0 讨论(0)
提交回复
热议问题