I am building an Ionic2 app for which i created a WebAPI to fetch the data from db. I am calling the API and fetching data but when i do see in console ,all i see is undefined.
TS
setCountyValues(sState) {
    // this.selectedCounties = this.counties.filter(county => county.state_id == sState.id)
    this.zipcode.getCounties(sState)
      .subscribe(data => {
        this.selectedCounties = data;
        
      })
  }
  
  
  DataFetch() {
    this.sState = this.documentDetails[0].DocumentTypeDetails.State;
    this.stateObj = this.states.find(state => state.StateAbbr == this.sState);
    console.log(this.stateObj); //working fine now
    this.sState = this.stateObj.StateName;
    this.setCountyValues(this.stateObj.StateAbbr);
    this.sCounty = this.documentDetails[0].DocumentTypeDetails.County
    console.log(this.selectedCounties); //giving undefined
    this.countyObj = this.selectedCounties.find(county => county.RecName == this.sCounty)
    this.sCounty = this.countyObj.RecName;
    console.log(this.sCounty);
  }
  
   Autofill() {
    this.zipcode.getDocDetails()
      .subscribe(data => {
        this.documentDetails = data;
        this.DataFetch();
      })
  }
  
  HTML
ion-item>
    <ion-label>State</ion-label>
    <ion-select (ionChange)="setCountyValues(sState.StateAbbr)" [(ngModel)]="sState" >
      <ion-option [value]="sState" *ngFor="let sState of states" [selected]="sState">{{sState.StateName}}</ion-option>
    </ion-select>
  </ion-item>
  
  <ion-item >
    <ion-label>Counties</ion-label>
    <ion-select (ionChange)="setCityValues(sCounty.PageRec)" [(ngModel)]="sCounty">
      <ion-option [value]="sCounty" *ngFor="let sCounty of selectedCounties" [selected]="sCounty">{{sCounty.RecName}}</ion-option>
    </ion-select>
  </ion-item>
  <ion-item *ngIf="citylength>0">
    <ion-label>Cities</ion-label>
    <ion-select [(ngModel)]="sCity">
      <ion-option [value]="sCity" *ngFor="let sCity of selectedCities" [selected]="sCity">{{sCity.name}}</ion-option>
    </ion-select>
  </ion-item>
  <ion-item *ngIf="selectedCounties">
    <button ion-button round color="primary" (click)="clear()">Clear</button>
    <button ion-button round color="primary" (click)="goToOfficeDetail()">Office Detail Page</button>
  </ion-item>JSON
"DocumentTypeDetails": {
            "PageRec": "AL005",
            "State": "AL",
            "County": "Autauga County",
            "CityTown": null,
            "Zip": null,
            "ShowRecordingInfo": "true",
            "Deed": {
                "Checked": "True",
                "Pages": "1",
                "ConsiderationAmount": "150000"
            },
            "MortgageDeed": {
                "Checked": "False",
                "Pages": null,
                "NewDebtAmount": null
            },
            "MortgageRefi": {
                "Checked": "False",
                "Pages": null,
                "NewDebtAmount": null,
                "OriginalDebt": null,
                "UnpaidDebt": null
            },
            "Assignment": {
                "Checked": "False",
                "Pages": null,
                "Assignments": null
            },
            "ReleaseSatisfaction": {
                "Checked": "False",
                "Pages": null,
                "ReleasesSatisfactions": null
            },
            "Questions": {
                "Question": {
                    "Number": "Q4",
                    "Category": "Deed",
                    "Type": "bool",
                    "QuestionText": "Are the deed and mortgage being recorded at the same time?",
                    "Answer": "1"
                }
            }
        }The error what i am getting is "Cannot read property 'find' of undefined" when i a trying to populate countObj. When i am calling the setCountyValues method then selectedCounties should get populated now i know that is async data and all that but how do i populate it?
 
    