Angular2 +和nodejs中的错误POST http:abc / 404(未找到)

时间:2018-06-30 05:10:23

标签: mysql node.js angular async-await

我正在从我的http代码向angular2+文件中存在的数据库发出一个node.js请求。来自ajax的{​​{1}}调用命中angular2+文件,然后重定向到与数据库有连接的controller.js文件:

service.js

从数据库中的angular.ts ==> controller.js ==> service.js 文件将输出提供给service.js文件,然后对controller.js文件进行ajax调用:

angular.ts

但是,我遇到了错误:

service.js ==> controller.js ==> angular.ts

已更新     无法获取/ dashboard / experianEntireSuccess1 /

还有一个问题-

POST http://localhost:8096/dashboard/abcEntireSuccess1/ 404 (Not Found)

还有一个问题-

从具有我想要==>的数据的service.js中命中之后返回=> controller.js,这里获取的数据是不确定的。如下所示-

Nodejs上的输出-

输出-

service.js

   UnauthorizedError: No authorization token was found

controller.js

  closed connection
  yessss [ RowDataPacket { ....

我的整个代码: 已更新

abc.component.ts

  we are coming back to controller undefined

  some error occured of abcEntireSuccess1

abc.controller.js

viewAbcEntireSuccess1() {


var url = config.url;
var port = config.port;


this.http.post("http://" + url + ":" + port + "/dashboard  
  /abcEntireSuccess1/", this.emptyObj
  , { headers: new Headers({ 'Authorization': 'Bearer ' + 
    localStorage.getItem('Token') }) })
  .map(resultConnection => this.resultConnection = 
    resultConnection.json(), )
   .subscribe((res: Response) => {

     this.records = res;

     this.resultConnectionlength = this.resultConnection.length;

   });

 }

abc.service.js

  router.post('/experianEntireSuccess1',experianEntireSuccess1);
  module.exports = router;


    function abcEntireSuccess1(req, res) {


    dashboardService.abcEntireSuccess1(req.body)
      .then(function (result) {
        console.log("we are coming back to controller",result)
        if (result.length > 0) {
            console.log("we get data in node of abcEntireSuccess1 :: 
         " + Object.values(result));
            console.log(result.length + " record found  ");
            res.send(result);
           } 
         else {
            result=[];
            res.send(result);
         }
     })
     .catch(function (err) {
        res.status(400).send(err);
        console.log("some error occured of abcEntireSuccess1");
      });
      }

0 个答案:

没有答案