title: Why am I unable to access class properties inside of a passed function of an Angular component?
body: <p>I am using HTML 5 geolocation inside an Angular component:</p>
  <pre><code>...
      export class AngularComponent {
      ...
          constructor(private db: DatabaseService) {}
  
          // this function is assigned to an HTML button
          logCoords(message, action) {
          navigator.geolocation.getCurrentPosition(this.success, this.error, this.options);
          }
  
          success(pos) {
              function time() {
              ...
              }
              var crd = pos.coords;
              var lat = crd.latitude
              var long = crd.longitude
  
              let newCoordinates = {'lat': lat, 'long':long, 'time': time}
              this.db.addLocation(newCoordinates)
          }
      ...
      }
  ...
  </code></pre>
  <p>I want to store the result of the getCurrentPosition Method inside indexed db using an Angular service but I am unable to access any properties of the component class (this.db is null).</p>
  <p>Why I am unable to access this.db inside the success function and how I might be able to work around this?</p>