(TypeError: Cannot read property 'length' of null at HttpHeaders.applyUpdate) Angular 5, Http Client
Don't set Null value in Header
This problem may occur due to null value in header i.e.
cloned = req.clone({ headers: req.headers.append('token', token) // i.e. token is null})
to fix this, check variable before setting into header i.e.
if (token) { cloned = req.clone({ headers: req.headers.append('token', token) })}
try like this :
service.ts
login(credentials): Observable<any> { return this.http.post("http://localhost:3000/api/Users/login", { username: credentials.username, password: credentials.password }).map(data => data.json())}
component.ts
onLogin(credentials) { this.userService.login(credentials) .subscribe(data => { console.log('data', data); }, (error) => { console.log('error', error); })}