httpclient,angular5,ie
web前端-js教程
本篇文章主要介绍了angular5 httpclient的示例实战,现在分享给大家,也给大家做个参考。3m互助平台系统源码,联想怎么进ubuntu,tomcat如何修改地址,pypython爬虫教程,php典例,移动seo优化和排名技术怎么用lzw
从angular 4.3.0 以后的版本开始使用httpclient,替换了之前的http,引用的包路径已经变为了angular/common/http了论坛带商城源码免费下载,光盘安装ubuntu慢,python爬虫日志感想,php获取文件夹内最新文件,亚马逊seo教学lzw
一个基础的 httpclient 样例仿叫我修吧源码,Ubuntu重启没有中文,爬虫多久可以入门,php 一周课程表,家居seo专家lzw
import { Injectable } from '@angular/core';import { HttpClient, HttpResponse } from '@angular/common/http';import { Observable } from 'rxjs/Observable';import { HttpDefaultOptions } from './http.default.options';@Injectable()export class Service { private static METHOD_DELTE = 'DELETE'; private static METHOD_POST = 'POST'; private static METHOD_GET = 'GET'; private static METHOD_PUT = 'PUT'; constructor(private httpClient: HttpClient) { } /** * 将数据上传 * @param data * @param {Function} func */ uploadDataPost(data: any, func: Function) { let url = '/api/test'; this.apiPost(url, data) .subscribe((response: HttpResponse) => { func(response); }, error => { func(undefined); }); } /** * 返回json 格式的obj 对象 * @param url * @param body * @param urlSearchParams * @returns {Observable} */ apiPost(url, body, urlSearchParams?: any): Observable { let options = { body: body ? body : null, params: urlSearchParams, responseType: 'json' }; return this.httpClient.request(Service.METHOD_POST, url, options); } /** * 返回一个obj 对象 * @param url * @param urlSearchParams url 的查询参数 * @returns {Observable} */ apiGet(url, urlSearchParams?: any): Observable { let options = { params: urlSearchParams, responseType: 'json' }; return this.httpClient.request(Service.METHOD_GET, url, options); }}
上面是我整理给大家的,希望今后会对大家有帮助。
相关文章:
Vue 自定义动态组件实例详解
javascript性能优化之分时函数的介绍
JavaScript中的E-mail 地址格式验证