title: Error : Cannot read property 'token' of null
body: <p>I am heaving some trouble with getting the token for login in my Angular App / API REST
  Here is the components et services I used.
  The registration part works fine, I even get all the intel in my DB in the right types but the main problem is with login.
  All the imports are correct I think.</p>
  
  <pre><code>export class LoginComponent implements OnInit {
  
    loginForm: FormGroup;
    username = '';
    password = '';
    isLoadingResults = false;
  
    constructor(private formBuilder: FormBuilder, private router: Router, private authService:
      AuthService) {}
  
    ngOnInit() {
      this.loginForm = this.formBuilder.group({
        'username': [null, Validators.required],
        'password': [null, Validators.required]
      });
    }
  
    onFormSubmit(form: NgForm) {
      this.authService.login(form)
        .subscribe(res =&gt; {
          console.log(res);
          if (res.token) {
            localStorage.setItem('token', res.token);
            this.router.navigate(['ads']);
          }
        }, (err) =&gt; {
          console.log(err);
        });
    }
  
    register() {
      this.router.navigate(['register']);
    }
  }
  </code></pre>
  
  <p>And here is my authorization service:</p>
  
  <pre><code>const apiUrl = 'http://localhost:9191/';
  
  const httpOptions = {
    headers: new HttpHeaders({
      'Content-Type': 'application/json',
      'Allow-Control-Access-Origin': '*'
    })
  };
  
  
  @Injectable({
    providedIn: 'root'
  })
  export class AuthService {
    isLoggedIn = false;
    redirectUrl: string;
  
    constructor(private http: HttpClient) {}
  
    login(data: any): Observable&lt;any&gt; {
      return this.http.post&lt;any&gt;(apiUrl + 'login', data, httpOptions)
        .pipe(
          tap(_ =&gt; this.isLoggedIn = true),
          catchError(this.handleError('login', []))
        );
    }
    register(data: any): Observable&lt;any&gt; {
      return this.http.post&lt;any&gt;(apiUrl + 'users/signup', data, httpOptions)
        .pipe(
          tap(_ =&gt; this.log('login')),
          catchError(this.handleError('login', []))
        );
    }
    //handleError and log methods here
  </code></pre>