订阅登录组件时,login方法抛出错误。声明类型既不是'void'也不是'any'的函数必须返回一个值

时间:2019-02-10 09:18:58

标签: angular

enter image description here

login(email: string, pass: string): Observable {
  const headers = {
    headers: new HttpHeaders({
      'Content-Type': 'application/x-www-form-urlencoded',
      'Cache-Control': 'no-cache',
    })
  };
  const data = {
    email: email,
    password: pass
  };
  const model = 'username=' + data.email + '&password=' + data.password + '&grant_type=' + 'password';
  this.http.post(this.API_URL, model, headers).pipe(map(res => {
    return res;
  }), catchError(this.handleError));
}

1 个答案:

答案 0 :(得分:0)

尝试一下

login(email: string, pass: string): Observable {
 const headers = {
  headers: new HttpHeaders({
   'Content-Type': 'application/x-www-form-urlencoded',
   'Cache-Control': 'no-cache',
  })
};
const data = {
  email: email,
  password: pass
 };
 const model = 'username=' + data.email + '&password=' + data.password + 
 '&grant_type=' + 'password';
 return this.http.post(this.API_URL, model, headers).pipe(map(res => {
   res.json();
 }), catchError(this.handleError)); 
}