柳州网站建设招聘,wordpress 音乐主题模板,最大的做网站公司,简易购物网站模板Rx 对象上有一个 ajax 运算符。const ajax: any;描述它使用以下请求对象创建 Ajax 请求的可观察对象#xff1a; 网址#xff0c;标头等或网址字符串。使用 ajax()来获取从 API 返回的响应对象。import { ajax } from rxjs/ajax;import { map, catchError } from rxjs/operat…Rx 对象上有一个 ajax 运算符。const ajax: any;描述它使用以下请求对象创建 Ajax 请求的可观察对象 网址标头等或网址字符串。使用 ajax()来获取从 API 返回的响应对象。import { ajax } from rxjs/ajax;import { map, catchError } from rxjs/operators;import { of } from rxjs;const obs$ ajax(https://api.github.com/users?per_page5).pipe(map(userResponse console.log(users: , userResponse)),catchError(error {console.log(error: , error);return of(error);}));使用 ajax.getJSON()从 API 获取数据。import { ajax } from rxjs/ajax;import { map, catchError } from rxjs/operators;import { of } from rxjs;const obs$ ajax.getJSON(https://api.github.com/users?per_page5).pipe(map(userResponse console.log(users: , userResponse)),catchError(error {console.log(error: , error);return of(error);}));将 ajax()与对象一起用作参数并将方法 POST 延迟两秒钟。import { ajax } from rxjs/ajax;import { of } from rxjs;const users ajax({url: https://httpbin.org/delay/2,method: POST,headers: {Content-Type: application/json,rxjs-custom-header: Rxjs},body: {rxjs: Hello World!}}).pipe(map(response console.log(response: , response)),catchError(error {console.log(error: , error);return of(error);}));使用ajax()获取。 从请求返回的错误对象。import { ajax } from rxjs/ajax;import { map, catchError } from rxjs/operators;import { of } from rxjs;const obs$ ajax(https://api.github.com/404).pipe(map(userResponse console.log(users: , userResponse)),catchError(error {console.log(error: , error);return of(error);}));