简体   繁体   English

属性“订阅”在类型“承诺”中不存在

[英]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.

相关问题 &#39;Promise&#39; 类型不存在属性 &#39;subscribe&#39; - Property 'subscribe' does not exist on type 'Promise' “OperatorFunction”类型上不存在属性“订阅”<response, {}> '</response,> - Property 'subscribe' does not exist on type 'OperatorFunction<Response, {}>' Angularfire错误:类型&#39;Promise&#39;中不存在“属性&#39;subscribe&#39; <any> &#39;。” - Angularfire error: “Property 'subscribe' does not exist on type 'Promise<any>'.” “承诺”类型上不存在属性“订阅” <observable<any> &gt;' </observable<any> - Property 'subscribe' does not exist on type 'Promise<Observable<any>>' &#39;Promise&#39; 类型不存在属性 &#39;subscribe&#39;<GraphQLResult> | 可观察的<object> &#39; - Property 'subscribe' does not exist on type 'Promise<GraphQLResult> | Observable<object>' Angular 2属性订阅在Promise类型上不存在<any> - Angular 2 Property subscribe does not exist on type Promise <any> Angular 6 Http订阅问题:类型“ Response”上不存在属性“ userInfo” - Angular 6 Http Subscribe issue: Property 'userInfo' does not exist on type 'Response' 类型&#39;OperatorFunction上不存在属性&#39;subscribe&#39; <Response, Recipe[]> “ - Property 'subscribe' does not exist on type 'OperatorFunction<Response, Recipe[]>' 属性“订阅”在类型上不存在 - Property 'subscribe' does not exist on type 类型“{}”上不存在属性“订阅” - Property 'subscribe' does not exist on type '{}'
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM