title: Javascript, calling function within promise
body: <h2>Explanation of code</h2>
  
  <p>I have a function called <code>placeDecode</code> which takes an HTML input element. Within the function I have a promise which converts input value into a formatted address.</p>
  
  <p>I called <code>placeDecode</code> twice, to check when both called have been resolved I use a Promise.all, checking both each function call. My problem arises when I try to call a function <code>viewResult</code>, I get <code>Cannot read property 'viewresult' of undefined</code> error.</p>
  
  <hr>
  
  <h2>Code</h2>
  
  <p><div class="snippet" data-lang="js" data-hide="false" data-console="true" data-babel="false">
  <div class="snippet-code">
  <pre class="snippet-code-js lang-js prettyprint-override"><code>  //call function twice
      var startAddress = this.placeDecode1(this.searches.startSearch);
      var endAddress = this.placeDecode1(this.searches.endSearch);
    
      //promise all
      Promise.all([endAddress,startAddress]).then(function(values) {
        this.viewResult(values);
  
      }).catch(function(result){
        console.log(result);
      })
  
      console.log('hit');
    }
  
  
    //method convertes input into formatted address
    private placeDecode1(input: HTMLInputElement) {
  
      var result = new Promise(function(resolve, reject) {
        var location = input.value;
  
        var geoCode = new google.maps.Geocoder();
        geoCode.geocode({
          address: location
        }, function(result,status){
          if(status == 'OK'){
            console.log(result[0].formatted_address);
            resolve(result[0].formatted_address);
          }
        })
      });
  
      return result;
  
    }</code></pre>
  </div>
  </div>
  </p>
  
  <hr>
  
  <h2>Problem</h2>
  
  <p>The problem I am having is when i call <code>this.viewResult(values);</code> , I get an </p>
  
  <p><code>Cannot read property 'viewResult' of undefined</code> Error.</p>
  
  <p>many thanks</p>