angular - 为 Nativescript 移动应用程序在本地开发 Golang 后端

标签 angular go localhost nativescript

我正在开发一个 Nativescript 移动应用程序,同时尝试设计一个 Golang 后端。我没有实际部署后端的经验,所以现在我只是想在本地开发。所以我的模拟应用程序上有一些按钮:

import { Http } from "@angular/http"                                                                

+@Component({...}
+export class LoginComponent implements OnInit {...}{

    . . .

    // <Button ... (tap)="get_test()"></Button> 
    public get_test(){                                                                              
        this.http.get("http://localhost:8080/");                                                    
    }                                                                                               

}  

还有一个我从 golang website 复制的小型网络服务器:

 package main

 import (
     "log"
     "net/http"
 )

 func handler(w http.ResponseWriter, r *http.Request) {
     print("recieved")
 }

 func main() {
     http.HandleFunc("/", handler)
     log.Fatal(http.ListenAndServe(":8080", nil))
 }

我启动go“服务器”:

go build main.go
./main

现在我的想法是,通过单击按钮,命令行应该打印出 recieved,我可以使用它来设计我的请求。然而,双方都没有任何反应。代码中可能有很多错误,我什至不确定您是否可以在本地进行模拟。但我们将不胜感激。

最佳答案

您的服务器端代码没有任何问题。在我看来,这听起来像是 (a) 您的前端代码实际上并未触发 http 请求(您应该能够通过附加到浏览器的调试器来检测到)或 (b) 您的前端正在尝试发出请求但没有不知道如何找到服务器(即网络问题)。

关于angular - 为 Nativescript 移动应用程序在本地开发 Golang 后端,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/49826426/

相关文章:

asp.net - 本地主机查找失败,浏览器尝试使用 www.localhost.com

javascript - typescript /Angular 传递值?

html - 如何在调整窗口大小(缩小)时将工具栏转换为侧边导航栏?

gob 解码器试图解码成非指针

go - 松弛集成 : 404 Expired url https://hooks. slack.com/commands

localhost - 远程访问localhost端口

java - selenium 3 AngularJS 单选无法选择在 selenium 2.53 中工作的内容

angular - 错误 TS2339 : Property 'loading' does not exist on type 'DiseaseListComponent'

go - 反射(reflection)传递给 interface{} 函数参数的结构

php - 设置 MySQL 和 Oracle 数据库 Mac OS X