title: Error: this.getToken is not a function
body: <p>I have a factory that returns 3 functions: <code>setToken</code>, <code>getToken</code>, <code>isAuthenticated</code>. The first two functions are predefined, and the last one calls the <code>getToken</code> function, using <code>this.getToken</code>.</p>
  
  <p>When injecting the factory into the controller, I then call the third function (<code>isAuthenticated()</code>), using <code>ng-show</code>. I get the following error in my console:</p>
  
  <blockquote>
    <p>Error: this.getToken is not a function<br>
    .isAuthenticated@<a href="http://localhost:9000/scripts/services/authtoken.js:22:16" rel="nofollow">http://localhost:9000/scripts/services/authtoken.js:22:16</a></p>
  </blockquote>
  
  <p>Can anybody help me with what I'm doing wrong?</p>
  
  <p><strong>The factory:</strong></p>
  
  <pre><code>'use strict';
  
  angular.module('psJwtApp').factory('authToken', function($window) {
    //define storage
    var storage = $window.localStorage;
    var cachedToken;
  
    // Public API here
    return {
      setToken: function(token) {
        cachedToken = token;
        storage.setItem('userToken', token);
      },
      getToken: function() {
        if (!cachedToken) {
          cachedToken = storage.getItem('userToken');
        }
        return cachedToken;
      },
      isAuthenticated: function() {
        //return true if we get something from getToken
        return !!this.getToken();
      }
    };
  
  });
  </code></pre>
  
  <p><strong>The Controller:</strong></p>
  
  <pre><code>'use strict';
  
  angular.module('psJwtApp').controller('HeaderCtrl', function($scope, authToken) {
      $scope.isAuthenticated = authToken.isAuthenticated;
  });
  </code></pre>
  
  <p><strong>The View:</strong></p>
  
  <pre><code>  &lt;ul class="nav navbar-nav"&gt;
      &lt;li ui-sref-active="active"&gt;
        &lt;a ui-sref="main"&gt;Home&lt;/a&gt;
      &lt;/li&gt;
      &lt;li ng-hide="isAuthenticated()" ui-sref-active="active"&gt;
        &lt;a ui-sref="register"&gt;Register&lt;/a&gt;
      &lt;/li&gt;
      &lt;li ng-show="isAuthenticated()" ui-sref-active="active"&gt;
        &lt;a ui-sref="logout"&gt;Logout&lt;/a&gt;
      &lt;/li&gt;
    &lt;/ul&gt;
  </code></pre>
  
  <p>If you feel that anything is missing or need more information, please ask and I'll add it to the question.</p>