Angular 7 http post 中未定义的“toLowerCase”
我浏览过一些论坛,但似乎找不到此问题。
我有一个身份验证服务,它应该使用令牌进行响应。
这是我的身份验证服务调用。
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/';