[英]Property 'subscribe' does not exist on type 'Promise<Response
I am making an http request to an api then want to console the result using .subscribe but facing this issue as Property 'subscribe' does not exist on type 'Promise'. 我向api发出一个HTTP请求,然后想使用.subscribe控制台结果,但是由于属性'subscribe'在'Promise'类型上不存在,因此面临此问题。
My Angular version is 6.2 and my Typescript version is 2.9 I also googled this and have done needful changes but the outcome is same . 我的Angular版本是6.2,我的Typescript版本是2.9,我也用谷歌搜索并进行了必要的更改,但结果是相同的。
my AuthService file is here 我的AuthService文件在这里
import { Injectable } from '@angular/core'
import { CONFIG } from '../config/config'
import { Http } from '@angular/http'
import 'rxjs/add/operator/toPromise'
@Injectable()
export class AuthService {
constructor(private http: Http) {
}
register(name: String, email: String, password: String) {
this.getConfig()
.subscribe((response => {
console.log(response)
}))
}
getConfig() {
return this.http.post(`${CONFIG.API_URL}/register`, { name: name, email: email, password: password }).toPromise()
}
}
Just remove toPromise()
只需删除toPromise()
getConfig() {
return this.http.post(`${CONFIG.API_URL}/register`, { name: name, email: email, password: password })
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.