alexrainman / nativescript-carousel-view

CarouselView plugin for NativeScript
MIT License
16 stars 5 forks source link

unable to get parent's property in xml #7

Closed terreb closed 7 years ago

terreb commented 7 years ago

nativescript 2.3.0 tns-core-modules 2.3.0 tns-ios 2.3.0 nativescript-carousel-view 2.0.1 simulator iOS 9.3

How to reproduce:

  1. add this to slider-view.xml in the demo app:
    <Label text="{{ $parents['CarouselView'].position, $parents['CarouselView'].position }}" />
  1. run the demo
alexrainman commented 7 years ago

@terreb i don't if you can access to $parents from a view loaded with builder. I will do my tests later on and let you know. Thanks

alexrainman commented 7 years ago

You can follow this https://github.com/NativeScript/NativeScript/issues/3077

alexrainman commented 7 years ago

{N} Team provided an example for this that i will be testing. Thanks

alexrainman commented 7 years ago

It seems that $parents doesn't provide access to the native widget properties but it's binding context instead, so if you want to access the CarouselView properties, you have to expose them in the ViewModel like this:

get position(): number {
   var page = frame.topmost().currentPage;
    var slider = <CarouselView>page.getViewById("carouselView");
    return slider.position;
}
terreb commented 7 years ago

ok, thanks