【发布时间】:2018-05-10 20:44:30
【问题描述】:
我正在尝试使用 nodejs、expressjs 和 Angular 5 构建一个小型服务器监视器/控制台。为了确定 apache 服务是否在远程服务器上运行,我构建了一个后端脚本,它试图从我要控制的服务器。问题是,我不知道如何从角度返回中获取http.get 的数据。在下面的示例中,我尝试将变量 this.apacheRunning 设置为 http.get 请求的响应。非常感谢您的帮助!
getApacheRunning(): Observable<String>{
this.apacheRunning = this.http.get("http://localhost:3000/ison").subscribe(result => this.apacheRunning = result,(err) => console.log(err), ()=> console.log("done"));
console.log(this.result);
if(this.apacheRunning == "true"){
console.log(this.apacheRunning + "DEBUG2");
return of("true");
}else{
console.log(this.apacheRunning + "DEBUG1");
return of("false")
}
}
代码在 gitHub 下:https://github.com/Clemens-Dautermann
【问题讨论】:
标签: node.js angular express httprequest angular5