title: Why is my injectable angular service class not saving class variables as expected?
body: <ol>
  <li>in constructor, console.log ("My ID is:") prints out the correct ID generated by the server.</li>
  <li>in getServerNotificationToken(), this.userID is returned as 'undefined' to the server, and prints as such.</li>
  </ol>
  
  <p>WHY is my class not saving it's variables on the class? My understanding of ES6 javascript is that the 'this' keyword is bound to the class itself, regardless of which function it is being used in.</p>
  
  <p>Thanks!</p>
  
  <pre><code>@Injectable({
    providedIn: 'root'
  })
  export class GamestateService {
    public socket: any;
    public userID: number;
  
    constructor(private firebaseMessaging: FirebaseMessaging, public navCtrl:NavController) {
      this.socket = io('http://192.168.1.3:3001');
      this.socket.on('push-client-id', (data) =&gt; {
        this.userID = data.id;
        console.log("My ID is:", this.userID);
      })
      this.getServerNotificationToken();
    }
  
    getID():number {
      return this.userID;
    }
  
    getServerNotificationToken() {
      console.log("In firebase messaging...");
      this.firebaseMessaging.getToken().then((token) =&gt; {
        console.log("Token received: ", token);
        let tokenResponseObj = {
          token,
          userId: this.userID
        }
        console.log("My user id:", this.userID);
        console.log("tokenResponseObj.userId:", tokenResponseObj.userId);
        console.log("tokenResponseObj.token:", tokenResponseObj.token);
        this.socket.emit('token-received', tokenResponseObj);
      });
    }
  }
  </code></pre>
  
  <p>expected: userID # assigned by server
  result: undefined</p>