JoshDSommer / nativescript-ngx-slides

A NativeScript + Angular module for to add a slides component to your mobile app
Other
45 stars 34 forks source link

How to use nextSlide() and previousSlide() from Typescript? #38

Closed anaszgh closed 6 years ago

JoshDSommer commented 6 years ago

Hi @anaszgh, you will need to used angular's ViewChild decorator to get the element. you can then access all the public functions on it.

Here is a stack overflow post I commented on that uses a StackLayout. It' the same idea. https://stackoverflow.com/questions/37884142/in-nativescript-with-angular2-how-can-i-get-an-interface-element-the-id/37884606#37884606

anaszgh commented 6 years ago

It returns undefined!

this it my markup

` <slides [pageIndicators]="true" (changed)="onChanged($event)" (finished)="onFinished()">

    <slide class="slide-2">
        <image src="~/images/intro_img_2.png"></image>
        <Label text="Title"></Label>
        <TextView text="this is a short paragraph this is a short paragraph this is a short paragraph this is a short paragraph "></TextView>

        <button text="Next" ></button>
    </slide>
    <slide class="slide-3">
        <image src="~/images/intro_img_3.png"></image>
        <Label text="Title"></Label>
        <TextView text="this is a short paragraph this is a short paragraph this is a short paragraph this is a short paragraph "></TextView>

        <button text="Next" ></button>
    </slide>
</slides>

`

and this it the TS initialization that results in undefined

@ViewChild("slides") slides: ElementRef;

public ngAfterViewInit(){ console.log(this.slides); }

JoshDSommer commented 6 years ago

@anaszgh you nedd to add a querySelector to the slides component .

<slides #slides .....

Hope that helps