1

我正在使用 Parse REST API 使用 Angular2 获取一些数据,一切正常,但我需要按降序获取数据,返回 Parse 文档,应该执行以下操作:

curl -X GET \
-H "X-Parse-Application-Id: appID" \
-H "X-Parse-REST-API-Key: keyID" \
-G \
--data-urlencode 'order=-score' \
https://api.parse.com/1/classes/GameScore

我想在我的Angular2代码中模拟那个cURL,我主要需要的是实现:data-urlencode

目前,这是我的 Angular2 代码:

this.http.get('https://example.com/classes/GameScore').subscribe(data => {
    this.res = data.json().results;
});
4

1 回答 1

2

您应该查看URLSearchParams有助于您形成查询字符串的 API。在使用它之前,请URLSearchParamsangular2/http

代码

import {URLSearchParams} from 'angular2/http'; //do add this line

var search = new URLSearchParams()
search.set('order', '-score');

this.http.get('https://example.com/classes/GameScore', { search }).subscribe(data => {
    this.res = data.json().results;
});
于 2016-04-19T14:48:45.970 回答