2017-08-19 13 views
-1

それがこれを引き起こしている何到達不能コードコンパイル時のエラー:到達不能コードは、このラインで

resolve(data) 

示して?

マイコード:

zipCodeBlurEventCall(zipcode) { 
    if (!this.validationService.isValidZipCodeRequired(this.siteDetail.ZipCode)) { 
     this.clearInvalidFlags(); 
     this.invalidZipCode = true; 
     this.siteDetail.WeatherLocation = ""; 
     this.toastr.error("Please enter valid Zip Code"); 
    } 
    else {    
     this.siteLoading = true; 
     this.queryString = "?zipcode=" + zipcode; 

     return new Promise((resolve, reject) => { 
      this.siteService.getStationByZipCode(this.queryString).then(data => { 
       this.element = data; 

       if (this.element == null) { 
        this.siteLoading = false; 
        this.invalidZipCode = true; 
        this.toastr.error("Invalid Zip Code"); 
        return true; 

       } else { 
        this.siteDetail.StateName = this.states.find(item => item.StateId === this.siteDetail.StateId).StateName; 
        if (this.siteDetail.StateName.toLowerCase() == this.element.response.place.stateFull.toLowerCase()) { 

         this.siteDetail.WeatherLocation = this.element.response.place.name; 
         this.isWeatherFlag = true; 
         this.siteLoading = false; 
         this.invalidZipCode = false; 
         return false; 
        } 

        else { 
         this.siteLoading = false; 
         this.invalidZipCode = true; 
         this.toastr.error("Zip code does not match with the selected State"); 
         return true; 
        } 
       } 

       resolve(data);     
      }); 

    });    

    } 
} 
+0

は、私はちょうど目が覚めたが、それはあなたが常にそれが実行されることはありませんつまり、到達することができますresolve' '前に戻るかのように表示されます。解決が呼び出された後に関数から戻ります。あなたの括弧はうんざりしているので、スコープが何であるかを見るだけでは分かりません。 – Carcigenicate

答えて

0

どこ、私はあなたがここに「true」または「false」の値を返すされている理由はわからないが、あなたはまだあなたのコードが動作するようにしたい場合は次のように行うことができます

zipCodeBlurEventCall(zipcode) { 
    if (!this.validationService.isValidZipCodeRequired(this.siteDetail.ZipCode)) { 
     this.clearInvalidFlags(); 
     this.invalidZipCode = true; 
     this.siteDetail.WeatherLocation = ""; 
     this.toastr.error("Please enter valid Zip Code"); 
    } 
    else {    
     this.siteLoading = true; 
     this.queryString = "?zipcode=" + zipcode; 

     return new Promise((resolve, reject) => { 
      this.siteService.getStationByZipCode(this.queryString).then(data => { 
       this.element = data; 
       let returnVal; 
       if (this.element == null) { 
        this.siteLoading = false; 
        this.invalidZipCode = true; 
        this.toastr.error("Invalid Zip Code"); 
        returnVal = true; 

       } else { 
        this.siteDetail.StateName = this.states.find(item => item.StateId === this.siteDetail.StateId).StateName; 
        if (this.siteDetail.StateName.toLowerCase() == this.element.response.place.stateFull.toLowerCase()) { 

         this.siteDetail.WeatherLocation = this.element.response.place.name; 
         this.isWeatherFlag = true; 
         this.siteLoading = false; 
         this.invalidZipCode = false; 
         returnVal = false; 
        } 

        else { 
         this.siteLoading = false; 
         this.invalidZipCode = true; 
         this.toastr.error("Zip code does not match with the selected State"); 
         returnVal = true; 
        } 
       } 

       resolve(data); 
       return returnVal;    
      }); 

    });    

    } 
} 
関連する問題