如何从订阅中返回值?

时间:2020-12-24 16:04:18

标签: angular typescript subscription

我有一个函数,它在订阅中进行查询和处理。如果查询成功,则该函数必须返回 200 或其他情况下的错误代码。我需要做什么才能返回我在订阅中获得的价值?

public loginEmail(email: string, password: string): Subscription {
    return this.http.post < any > (`http://127.0.0.1:8080/user/`, {}, {
            params: new HttpParams().set('email', email).set('password', password)
        })
        .subscribe(resp => {
            console.log(resp);
            this.user.setUser(resp['user'])
            return 200;
        }, error => {
            return error.code
        });
}

0 个答案:

没有答案