title: Confusion about 'this' keyword in angular 'controller as' syntax
body: <p>I have a parent controller, <code>UserEditCtrl</code> and a child controller, <code>EditUserCtrl</code>. Inside of my parent controller I am pulling in a user object via a service:</p>
  
  <pre><code>userMgmtSvc.user(scope.editUserId).then(function(data) {
    this.user = data;
  });
  </code></pre>
  
  <p>Then I want to set a property of my user object to another variable.</p>
  
  <pre><code>this.selectedRoles = this.user.roles;
  </code></pre>
  
  <p>But this throws an error:</p>
  
  <pre><code>Cannot read property 'user' of undefined.
  </code></pre>
  
  <p>I'm confused as to how I reference objects that are set with <code>this</code>. For example, how do I just console.log the object? Because <code>console.log('user', this.user);</code> returns undefined:</p>
  
  <pre><code>user undefined
  </code></pre>
  
  <p>Here's the parent controller:</p>
  
  <pre><code>(
    function (app) {
      /* @fmt: off */
      'use strict';
  
      // @fmt:on
      app.controller('UserEditCtrl', ['$scope', '$http', 'userMgmtSvc', 'createUserSvc', 'authSvc', '$state', '$timeout', '$location', '_',
        function (scope, http, userMgmtSvc, createUserSvc, authSvc, state, timeout, location, _) {
  
        userMgmtSvc.user(scope.editUserId.id || sessionStorage.getItem('editUser')).then(function(data) {
          this.user = data;
          console.log('user', this.user);
  
        // GET states
        createUserSvc.states().then(function(data) {
            this.states = data;
            console.log(this.states);
        });
  
        // GET countries
          createUserSvc.countries().then(function(data) {
          this.countries = data;
        });
  
        // GET roles
        createUserSvc.roles().then(function(data) {
          this.roles = data;
        });
  
        // GET insurance groups
        createUserSvc.insuranceGroups().then(function(data) {
          this.insuranceGroups = data;
        });
  
        this.selectedRoles = this.user.roles;
      });
  
   }]);
  
  }(window.app)
  );
  </code></pre>