簡體   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