嗨我是角度非常新的,我从角度服务调用API,但是在第一次点击时,它直接捕获并在订阅中,数据就像输入的意外结束一样,但是几分钟之后它就会被击中API和extractData方法也受到特定成功json的影响: 服务:
getUsers(userName: string, password: string): Observable<any> {
debugger;
return this._http.get("http://localhost:51802/Login?userName=" + userName + "&password=" + password)
.map((this.extractData))
.catch(this._errorHandler);
}
private extractData(res: Response) {
return res.text() ? res.json() : {};
}
_errorHandler(error: Response) {
console.error(error);
return Observable.throw(error || "Server Error");
}
成分:
public loginUsers(loginId: string, password: string) {
console.log(this.loginForm);
if (this.loginForm.valid) {
this._loginService.getUsers(loginId, password).subscribe(data => this.users = data);
// this.users = this._loginService.getUsers(body);
console.log('form submitted');
// this.router.navigateByUrl('index');
} else {
this.validateAllFormFields(this.loginForm);
}
}
答案 0 :(得分:0)
试试这个,
this.http.get('http://localhost:51802/api/acc/Login?userName=' + userName + '&password=' + password)