繁体   English   中英

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

[英]login method is throwing error while subscribing in login component.A function whose declared type is neither 'void' nor 'any' must return a value

在此处输入图片说明

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));
}

尝试这个,

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)); 
}

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM