Javascript Api调用不返回数据。http.get()

Javascript Api调用不返回数据。http.get(),javascript,api,angular,get,Javascript,Api,Angular,Get,我正在尝试从API获取数据。我得到的只是204状态。我的数据库中有数据,当在POSTMAN中调用时,它会发送正确的数据 这是集合。ts: ngOnInit() { console.log("this is collections page") this.loanService.getCollectionList().subscribe(response => { this.collections = response; })

我正在尝试从API获取数据。我得到的只是204状态。我的数据库中有数据,当在POSTMAN中调用时,它会发送正确的数据

这是
集合。ts

ngOnInit() {
        console.log("this is collections page")

    this.loanService.getCollectionList().subscribe(response => {
          this.collections = response;
      })
    console.log(this.collections)
  }
这是我的贷款服务

 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)
  }

由于http调用是一个异步操作,因此处理响应需要一段时间。您的
this.collections
将仅在响应到达回调(subscribe)时定义

看看这篇很棒的帖子:

改变

ngOnInit() {
        console.log("this is collections page")

    this.loanService.getCollectionList().subscribe(response => {
          this.collections = response;
      })
    console.log(this.collections)
  }

由于http调用是一个异步操作,因此处理响应需要一段时间。您的
this.collections
将仅在响应到达回调(subscribe)时定义


看看这篇很棒的帖子:

@hemanthkoganti取决于你如何使用它。在您的问题中包含html。@hemanthkoganti取决于您如何使用它。在问题中包含html。