有一个帖子请求
var a = [
{name:'james',grade:'A'},
{name:'john',grade:'B'},
{name:'iris',grade:'A'},
{name:'ivan',grade:'C'}
];
a.filter(function(e) {
return (e.grade == 'A') || (e.grade == 'C');
});
我在Angular 2中这样做,但她不工作,为什么? 在请求中,我需要传输项目ID列表。 作为回报,获取xls文件,但我无法做到。我发了一个帖子请求,但我无法将其翻译成Angular
var settings = {
"async": true,
"crossDomain": true,
"url": "http://localhost:32001/api/job/jobs-list-excel",
"method": "POST",
"headers": {
"content-type": "application/json",
"cache-control": "no-cache",
"postman-token": "9135e481-df69-b870-4f72-92873c1fd7de"
},
"processData": false,
"data": "{\"jobIds\": [2,3]}"
}
$.ajax(settings).done(function (response) {
console.log(response);
});
答案 0 :(得分:0)
import {Headers, RequestOptions} from 'angular2/http';
let body = JSON.stringify({ 'jobIds': '[2,3]' });
let headers = new Headers({ 'Content-Type': 'application/json' },{'cache-control':'no-cache'},{'postman-token':'9135e481-df69-b870-4f72-92873c1fd7de'});
let options = new RequestOptions({ headers: headers });
let url = 'http://localhost:32001/api/job/jobs-list-excel';
return this.http.post(url, body, options)
.map(res => res.json().data)
.catch(this.handleError)