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

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

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

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)

最佳答案

更改

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




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

关于angular - Angular 7 http post中未定义的“toLowerCase”,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/54206815/

10-12 20:55