Вы можете использовать двустороннюю привязку ListPicker для доступа к selectedIndex
сборщика. Просто используйте угловой 2 двухсторонние связывания синтаксиса [(ngModel)] и установите его на номер свойство компонента:
<ListPicker [items]="locations" [(ngModel)]="selectedLocationIndex"></ListPicker>
и вот пример кода за такой угловой компонент:
import { Component, OnInit } from "@angular/core";
import { ObservableArray } from "data/observable-array";
import { DataService } from "../data.service";
import * as DependencyObservableModule from "ui/core/dependency-observable";
import * as ProxyModule from"ui/core/proxy";
@Component({
moduleId: module.id,
selector: "my-component",
providers: [DataService],
templateUrl: MyComponent.html',
styleUrls: ["MyComponent.css"]
})
export class MyComponent extends DependencyObservableModule.DependencyObservable implements OnInit {
private static selectedLocationIndexProperty = new DependencyObservableModule.Property(
"selectedLocationIndex",
"MyComponent",
new ProxyModule.PropertyMetadata(
undefined,
DependencyObservableModule.PropertyMetadataSettings.None,
MyComponent.onSelectedLocationIndexPropertyChanged));
private static locationsProperty = new DependencyObservableModule.Property(
"locations",
"MyComponent",
new ProxyModule.PropertyMetadata(
undefined,
DependencyObservableModule.PropertyMetadataSettings.None));
private static currentLocationroperty = new DependencyObservableModule.Property(
"currentLocation",
"MyComponent",
new ProxyModule.PropertyMetadata(
undefined,
DependencyObservableModule.PropertyMetadataSettings.None));
constructor(private _dataService: DataService) {
super();
}
ngOnInit() {
this.locations = new ObservableArray(this._dataService.getDrawerLocations());
this.currentLocation = SideDrawerLocation.Left;
this.selectedLocationIndex = 0;
}
get selectedLocationIndex(): number {
return this._getValue(MyComponent.selectedLocationIndexProperty);
}
set selectedLocationIndex(value: number) {
this._setValue(MyComponent.selectedLocationIndexProperty, value);
}
get locations(): ObservableArray<SideDrawerLocation> {
return this._getValue(MyComponent.locationsProperty);
}
set locations(value: ObservableArray<SideDrawerLocation>) {
this._setValue(MyComponent.locationsProperty, value);
}
get currentLocation(): SideDrawerLocation {
return this._getValue(MyComponent.currentLocationroperty);
}
set currentLocation(value: SideDrawerLocation) {
this._setValue(MyComponent.currentLocationroperty, value);
}
private static onSelectedLocationIndexPropertyChanged(args) {
var myComp: MyComponent = args.object;
myComp.onSelectedLocationIndexChanged(args);
}
private onSelectedLocationIndexChanged(args) {
this.currentLocation = this.locations.getItem(this.selectedLocationIndex);
}
}
Этот фрагмент кода взят из примера this из примера nativescript-ui-samples-angular github repo, здесь вы найдете много полезных примеров.