将发布函数从Angular 5转换为6

时间:2018-09-10 20:33:16

标签: angular5 angular6

我正在将git应用程序的这一部分转换为Angular6。 (我认为没有必要看它)

https://github.com/mmacneil/AngularASPNETCore2WebApiAuth/blob/master/src/src/app/shared/services/user.service.ts

该应用程序已充满了对.netApi的所有调用,因此,修复此漏洞后,我将有希望地将它们全部转换。

这就是我要使用的功能。

旧的V5登录

 login(userName, password) {
let headers = new Headers();
headers.append('Content-Type', 'application/json');

return this.http
  .post(
  this.baseUrl + '/auth/login',
  JSON.stringify({ userName, password }),{ headers }
  )
  .map(res => res.json())
  .map(res => {
    localStorage.setItem('auth_token', res.auth_token);
    this.loggedIn = true;
    this._authNavStatusSource.next(true);
    return true;
  })
  .catch(this.handleError);
}

我的进行中版本

 login(userName, password) {
const httpOptions = {
  headers: new HttpHeaders({
    'Content-Type':  'application/json'
  })
};
return this.http
  .post(
  this.baseUrl + '/auth/login',
  JSON.stringify({ userName, password }), httpOptions 
  )   
  .pipe(
    map(res => {
      localStorage.setItem('auth_token', res.auth_token);
      this.loggedIn = true;
      this._authNavStatusSource.next(true);
      return true;
    }),
    catchError(this.handleError)
  ); 
 }

首先我在正确的道路上,其次 我遇到了错误   res.auth_token

类型“对象”上不存在属性“ auth_token”。

当然不是,但是我如何做旧代码。 (或者我需要)。

这一切都没有运行,但仅在“ Visual Code”中存在错误。

0 个答案:

没有答案