title: Angular 4 - Store data in localStorage when login is successful
body: <p>I have a login function and I want to store the data in localstorage only when the login is valid, but in my case, even the login is invalid it still store the data in localstorage.</p>
  
  <p><strong>component</strong></p>
  
  <pre><code> onSubmit = function(formData) {
     this._membersService.login(formData);
     localStorage.setItem('loginSessId', formData.acct_username);
   }
  </code></pre>
  
  <p><strong>service</strong></p>
  
  <pre><code>login(data) {
    return this._http.post('http://localhost/membership/main/login', data)
    .subscribe(data =&gt; data);
  }
  </code></pre>