title: Uncaught (in promise): TypeError: Cannot read property 'userSubject' of undefined TypeError: Cannot read property 'userSubject' of undefined
body: <p>I want to call</p>
  
  <pre class="lang-js prettyprint-override"><code>login(username, password) {    
    return Parse.User.logIn(username, password)
      .then(function (user) {
        // store user details and jwt token in local storage to keep user logged in between page refreshes
        localStorage.setItem('user', JSON.stringify(user));
        console.log(user);
        this.userSubject.next(user);
        return user;
      });
  }
  </code></pre>
  
  <p>same like this</p>
  
  <pre class="lang-js prettyprint-override"><code>login(username, password) {
    return this.http.post&lt;user&gt;(`${environment.apiUrl}/users/authenticate`, { username, password })
      .pipe(map(user =&gt; {
        // store user details and jwt token in local storage to keep user logged in between page refreshes
        localStorage.setItem('user', JSON.stringify(user));
        console.log(user);
        this.userSubject.next(user);
        return user;
    }));
  }
  </code></pre>
  
  <p>but it is resulting in error</p>
  
  <pre><code>Uncaught (in promise): TypeError: Cannot read property 'userSubject' of undefined
  TypeError: Cannot read property 'userSubject' of undefined
  </code></pre>