JoshDSommer / nativescript-slides

A NativeScript plugin that is for Intro Tutorials, Image Carousels or any other slide functionality
Other
70 stars 32 forks source link

ERROR TypeError: Cannot read property 'object' of undefined #114

Closed HartzDev closed 6 years ago

HartzDev commented 6 years ago

hello guys, iam still new in nativescript+angular. and now iam developing an app that need use slide. and every time i slide , i have to change color of indicator. and i wanna get current index of what slide i am at.

this is my Html : <Slides:SlideContainer angular="true" #slides pageIndicators="true" pagerOffset= "75%" (changed)="OnChange()">

and this is my .ts : import { Component, ElementRef, OnInit, ViewChild } from "@angular/core"; import {registerElement} from "nativescript-angular/element-registry"; import { Page } from "ui/page"; import * as slide from 'nativescript-slides/nativescript-slides' registerElement("Slide", () => require("nativescript-slides").Slide); registerElement("SlideContainer", () => require("nativescript-slides").SlideContainer); @Component({ selector: "LoginPage", moduleId: module.id, templateUrl: "./login-page.component.html", styleUrls: ["./login-page.component.css"] }) export class LoginPageComponent implements OnInit { @ViewChild("slides") slides: ElementRef; constructor(private page : Page) { /* *********************************************************** * Use the constructor to inject app services that you need in this component. *************************************************************/ page.actionBarHidden=true; } ngOnInit(): void { /* *********************************************************** * Use the "ngOnInit" handler to initialize data for this component. *************************************************************/ } OnChange(args){ let slideContainer = args.object; <-- this trigger the error console.log(slideContainer.currentIndex); } btnClicked(){ console.log("tab!!!"); } ngAfterViewInit() { let SlidesXml = this.slides.nativeElement; SlidesXml.constructView(); } } thx.
JoshDSommer commented 6 years ago

Hi @HartzDev, For angular usage please check out the package nativescript-ngx-slides. it's made specifically for angular.

https://www.npmjs.com/package/nativescript-ngx-slides