title: async function in angularjs app
body: <p>I am writing a service which returns a function but the function doesn't return a value. Here is the code:</p>
  
  <pre><code>function getUser() {
      var Users = $resource('/api/users',{},{query: {method: 'get', isArray: true}});
      return Users.query({username:localStorage.getItem("token")}).$promise
  }
  
  function userrole() {
      var userrole='';
  
      var tmp=getUser();
      tmp.then(function(user){
          var userrole= user[0].role;
          console.log('The role is '+user[0].role);
          userrole=user[0].role;
          return userrole;
      });
      console.log('@ the end of userrole');
  }
  </code></pre>
  
  <p>The function which doesn't return is <code>userrole</code>. I believe it's because of an async problem. How can I go about solving this?</p>