【发布时间】:2018-12-02 08:10:29
【问题描述】:
我正在向 api 发出 http 请求,然后想使用 .subscribe 来控制结果,但由于类型“Promise”上不存在属性“subscribe”而面临此问题。
我的 Angular 版本是 6.2,我的 Typescript 版本是 2.9。
我的 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()
}
}
【问题讨论】:
标签: angular typescript angular6