Search code examples
angulartypescriptnativescriptangular2-nativescript

get string value from observable array in angular2 nativescript


I pushed json datas into observable array.I need to get the only the address from ShowData.That means just a string type i need to get the address value based on the position.

ShowData.ts:

 class ShowData{

  constructor(public id:number, public name:string, public address:string, public code:string) {
  }

 }

ts file:

  private arrList: ObservableArray<ShowData> = new ObservableArray<ShowData>();

openData(pos : number){    --->listview item position


   let getValue: any = this.arrList.get(pos);  // this is not worked


}

Based on the listview item position, I need to get only the arrList address.


Solution

  • Observable arrays use .getItem to retrieve the item from array (not .get)

    openData(pos : number){   
       let getValue: any = this.arrList.getItem(pos).address;
    }