title: Angular 7 - HttpClient "Property 'success' does not exist on type Object"
body: <p>When someone registers, I post the info to my back-end. When successfully registering a user, I get a json response back of {success: true, msg: "User registered"}. My problem is when I try to do an if statement to check if success is set to true.</p>
  
  <p><strong>Here is my code that isn't working:</strong></p>
  
  <pre><code>    // Register User
      this.apiService.registerUser(user).subscribe(data =&gt; {
        if(data.success) {
          this.flashMessage.show('Registration successful', { cssClass: 'alert-success', timeout: 3200 });
        } else {
          this.flashMessage.show('Registration failed', { cssClass: 'alert-danger', timeout: 3200 });
        }
      });
  </code></pre>
  
  <hr>
  
  <p><strong>I was able to console.log the response of data, and it returned:</strong></p>
  
  <pre><code>{success: true, msg: "User registered"}
  </code></pre>
  
  <hr>
  
  <p><strong>Here is the code from my ApiService:</strong></p>
  
  <pre><code>import { Injectable } from '@angular/core';
  import { HttpClient, HttpHeaders } from '@angular/common/http';
  
  import { User } from '../models/User';
  
  @Injectable({
    providedIn: 'root'
  })
  export class ApiService {
    private baseUri: string = 'http://localhost:5000/api';
    private headers = new HttpHeaders().set('Content-Type', 'application/json');
  
    constructor(private http: HttpClient) { }
  
    registerUser(user: User) {
      return this.http.post(this.baseUri + '/register', user, { headers: this.headers });
    }
  }
  </code></pre>
  
  <hr>
  
  <p><strong>Here is the code from my Register Component:</strong></p>
  
  <pre><code>onRegisterSubmit() {
      const user: User = {
        firstName: this.firstName,
        lastName: this.lastName,
        email: this.email,
        username: this.username,
        password: this.password
      };
  
  // Register User
      this.apiService.registerUser(user).subscribe(data =&gt; {
        console.log(data);
      });
  
    }
  </code></pre>
  
  <p><a href="https://i.stack.imgur.com/9rCBR.png" rel="nofollow noreferrer">Screenshot of error from ng serve</a></p>
  
  <p>I'm quite new to working with angular let alone a back-end, so if you could explain why this error was occurring it would be greatly appreciated.</p>
  
  <p>Please let me know if you need any more information.</p>