0
私はAPIからデータを取得しようとしています。私が得るのは204ステータスです。 DBにデータがあり、POSTMANで呼び出されると適切なデータが送信されます。ここでデータを返さないAPI呼び出し。 http.get()
はcollections.ts
次のとおりです。ここ
ngOnInit() {
console.log("this is collections page")
this.loanService.getCollectionList().subscribe(response => {
this.collections = response;
})
console.log(this.collections)
}
は私loanServiceは、これは私のルートである
public getCollectionList(){
const path = this.basePath + '/collections'; // change the path
let queryParameters = new URLSearchParams();
let headerParams = this.defaultHeaders;
// queryParameters.set('','');
let requestOptions: RequestOptionsArgs = {
method: 'GET',
headers: headerParams
// search: queryParameters
};
return this.http.request(path, requestOptions)
.map((response: Response)=> {
if (response.status === 204) {
return undefined;
} else {
return response.json();
}
});
}
です - collection.js
:
router.get('/collections', function (req, res, next) {
// var errors = req.validationErrors();
if (errors) {
console.log('Errors');
res.status(400);
res.json(errors);
} else {
console.log(req.query);
// db.loans.find({ 'STATE' : state, 'LOAN_BRANCH' : loanBranch }, function(err, loans){
db.collections.find(req.query, function (err, collections) {
if (err) {
res.status(400);
res.send(err);
} else {
// console.log(collections);
res.json(collections);
}
})
}
});
ngOnInit() {
console.log("this is collections page")
this.loanService.getCollectionList().subscribe(response => {
this.collections = response;
console.log(this.collections)
})
}
へ
OK ....ので、私は直接テンプレート(collections.html)で、今のデータを使用できますか? –
@hemanthkogantiはあなたの使い方によって異なります。あなたの質問にhtmlを含めてください。 – echonax
うん、それは気にしていない........ありがとう@echonax –