Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/angular/26.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/http/4.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Angular 通过管道订阅时没有http请求()_Angular_Http_Angular2 Observables - Fatal编程技术网

Angular 通过管道订阅时没有http请求()

Angular 通过管道订阅时没有http请求(),angular,http,angular2-observables,Angular,Http,Angular2 Observables,我是angular的新手,尝试通过向我的服务器发送http请求来检查用户名是否已经存在,但我的服务器没有收到任何请求 为我服务: checkUsername(name: string): Observable<boolean> { return this.http.get( `${this.api}/checkusername/${name}` ).pipe( catchError(this.errorHandler) ); } 正如您所看到的,服务器打印每个名称,现在它回

我是angular的新手,尝试通过向我的服务器发送http请求来检查用户名是否已经存在,但我的服务器没有收到任何请求

为我服务:

checkUsername(name: string): Observable<boolean> {
return this.http.get(
  `${this.api}/checkusername/${name}`
).pipe(
  catchError(this.errorHandler)
);
}
正如您所看到的,服务器打印每个名称,现在它回答为{exists:false}

如果我把

this.vs.checkUsername(control.value).subscribe(val => console.log(val));

在我的验证功能中,服务器可以正确地接收所有内容。

对于从SERVICE获取请求,您始终需要
订阅

http.post(以及get、put、delete等)
返回一个cold
可观察的
,即一个
可观察的
,其:

其基础生产者在订阅期间创建和激活

这意味着只有使用
subscribe()
方法才能激活由可观察对象表示的函数


对于从SERVICE获取请求,您始终需要
订阅

http.post(以及get、put、delete等)
返回一个cold
可观察的
,即一个
可观察的
,其:

其基础生产者在订阅期间创建和激活

这意味着只有使用
subscribe()
方法才能激活由可观察对象表示的函数

app.get("/api/checkusername/:name", (req: express.Request, res: express.Response) => {
  console.log(req.params.name);
  res.json({exists: false});
});
this.vs.checkUsername(control.value).subscribe(val => console.log(val));
 post() : Promise<any> {
     return this.http.post(
       '/api, 
        {}
     ).toPromise();
post() {
    var observable = this.http.post('/api', {})
        .map(response => response.json()) // in case you care about returned json       
        .publishReplay(); // would be .publish().replay() 
    observable.connect();
    return observable;
}