Angular 7 http post中未定义的“ toLowerCase”

时间:2019-01-15 21:07:02

标签: angular

我读过一些论坛,但似乎找不到此问题。

我有一个身份验证服务,应该以令牌响应。

这是我的身份验证服务电话。

import { Injectable } from '@angular/core';
import { HttpClient } from '@angular/common/http';
import { map } from 'rxjs/operators';

@Injectable()
export class AuthService {
    baseUrl: 'https://api.website.com/login/';

    constructor(private http: HttpClient) { }

    login(model: any) {
        return this.http.post(this.baseUrl, model)
            .pipe(
                map(data => data)
            );
    }
}

在我的登录组件中,我有以下电话:

login() {
    this.auth.login(this.model)
      .subscribe(
        (data: any) => {
          console.log(data);
        },
        (error: any) => {
          console.log(error);
        }
      );
  }

但是我正在向控制台返回错误。我没有拦截器,也不确定这是哪里来的。有帮助吗?

TypeError: Cannot read property 'toLowerCase' of undefined
    at HttpXsrfInterceptor.push../node_modules/@angular/common/fesm5/http.js.HttpXsrfInterceptor.intercept (http.js:1719)
    at HttpInterceptorHandler.push../node_modules/@angular/common/fesm5/http.js.HttpInterceptorHandler.handle (http.js:1135)
    at HttpInterceptingHandler.push../node_modules/@angular/common/fesm5/http.js.HttpInterceptingHandler.handle (http.js:1770)
    at MergeMapSubscriber.project (http.js:975)
    at MergeMapSubscriber.push../node_modules/rxjs/_esm5/internal/operators/mergeMap.js.MergeMapSubscriber._tryNext (mergeMap.js:61)
    at MergeMapSubscriber.push../node_modules/rxjs/_esm5/internal/operators/mergeMap.js.MergeMapSubscriber._next (mergeMap.js:51)
    at MergeMapSubscriber.push../node_modules/rxjs/_esm5/internal/Subscriber.js.Subscriber.next (Subscriber.js:54)
    at Observable._subscribe (scalar.js:5)
    at Observable.push../node_modules/rxjs/_esm5/internal/Observable.js.Observable._trySubscribe (Observable.js:43)
    at Observable.push../node_modules/rxjs/_esm5/internal/Observable.js.Observable.subscribe (Observable.js:29)

1 个答案:

答案 0 :(得分:1)

更改

 baseUrl: 'https://api.website.com/login/';

 baseUrl= 'https://api.website.com/login/';