【问题标题】:Can't access NodeJS api from Angular app无法从 Angular 应用程序访问 NodeJS api
【发布时间】:2018-04-27 06:37:18
【问题描述】:

我无法从我的 Angular 应用程序访问我的 NodeJs 服务器。这是我的路由器:

app.get('/new12345',function(req,res){
    console.log("Http Get Recently Gone from /new12345");
    var results = userData;
    res.send(results);
});

在这里我尝试访问我的 api。

this.http.get('/new12345').subscribe(data => {
  this.resultInArray = data['results'];
}

我收到了this error

Error: Cannot match any routes. URL Segment: 'new12345'

谢谢!

【问题讨论】:

    标签: node.js angular mean-stack


    【解决方案1】:

    您没有指定您的 api 基本网址。您目前正在使用您的 Angular 应用程序(因此您会遇到 Angular 路由器错误)。

    例如,可能如下所示:

    this.http.get('http://localhost:3000/new12345').subscribe(data => {
        this.resultInArray = data['results'];
    }
    

    【讨论】:

    • 需要在哪里(在节点或角度)指定基本 api...我是 mea2n 堆栈中的新手...
    • 它对我不起作用...因为在控制台日志中没有在控制台中打印任何内容,例如...“Http Get Recent Gone from /new12345”,我打印它以检查我的应用程序已从"/new12345" 节点接口...
    猜你喜欢
    • 2018-06-01
    • 2021-12-07
    • 2019-12-25
    • 1970-01-01
    • 2019-06-27
    • 1970-01-01
    • 2019-09-16
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多