Angular module using a third-party data request axios

1, the installation axios

cnpm install axios --save

2, the place used to introduce axios

import axios from 'axios';

3 Create angular services ng g service services / httpservice

Axios introduced in httpservice.service.ts: axiosGet and write method used to obtain data related to background

Such HttpserviceService module incorporated in app.module.ts

 

 Where needed on where the introduction of

HttpserviceService class import {HttpserviceService} from "../../services/httpservice.service"; in assembly news.component.ts constructor function declaration so that the component can use the

 

 

 

 

Guess you like

Origin www.cnblogs.com/zhx119/p/11928384.html