Ionic slide lock swipe error


#1

I am trying to lock swipe
this is my ts file

import { Component } from '@angular/core';
import { IonicPage, NavController, NavParams,Slides  } from 'ionic-angular';

@IonicPage()
@Component({
  selector: 'page-service',
  templateUrl: 'service.html',
})

export class ServicePage {

  constructor(public navCtrl: NavController, public navParams: NavParams,public slides: Slides) {
    this.slides.lockSwipes(true);
  }

  ionViewDidLoad() {
    console.log('ionViewDidLoad ServicePage');
  }

}

an this is the error am getting

Uncaught (in promise): Error: No provider for Slides! Error: No provider for Slides! at injectionError 

#2

Nevermind… i fixed the error


#3

Can you share the solution for future readers?


#4
import { ViewChild } from '@angular/core';
import { Slides } from 'ionic-angular';


@IonicPage()
@Component({
  selector: 'page-service',
  templateUrl: 'service.html',
})


export class ServicePage {

  @ViewChild(Slides) slides: Slides;
  constructor(public navCtrl: NavController, public navParams: NavParams) {
    
  }

  ionViewDidLoad() {
    console.log('ionViewDidLoad ServicePage');
    this.slides.lockSwipes(true);
  }

}

#5

I am also facing the same error, here is my file

import {Component, ViewChild} from "@angular/core";
import {FormBuilder, FormGroup, Validators} from "@angular/forms";
import {NavController, NavParams, Slides, ViewController} from "ionic-angular";
import {Logger} from "../../../../providers/logger/logger";
import {OnGoingProcessProvider} from "../../../../providers/on-going-process/on-going-process";
import {PersistenceProvider} from "../../../../providers/persistence/persistence";


@Component({
    selector: 'modal',
    templateUrl: 'modal.html',
})
export class ModalPageForProfile {

    public profileForm: FormGroup;

    @ViewChild('profileSlider') profileSlider: any;
    @ViewChild(Slides) slides: Slides;

    public slideOneForm: FormGroup;
    public slideTwoForm: FormGroup;

    submitAttempt: boolean = false;




    constructor(
        private persistence: PersistenceProvider,
        private logger: Logger,
        private navCtrl: NavController,
        private navParams: NavParams,
        private onGoing: OnGoingProcessProvider,
        private formBuilder: FormBuilder,
        private view: ViewController

    ){

        this.logger.info("We are in modal");
        this.slides.lockSwipes(true);

        let emailRegex: RegExp = /^\w+([\.-]?\w+)*@\w+([\.-]?\w+)*(\.\w{2,3})+$/;

        let phoneRegex: RegExp = /^[(]{0,1}[0-9]{3}[)]{0,1}[-\s\.]{0,1}[0-9]{3}[-\s\.]{0,1}[0-9]{4}$/;

        this.slideOneForm = this.formBuilder.group({
            name: ['', Validators.compose([Validators.maxLength(30), Validators.pattern('[a-zA-Z ]*'), Validators.required])],
            email: ['', [Validators.required, Validators.pattern(emailRegex)]],
            deliveryDate: [''],
            phone: ['',[Validators.required, Validators.pattern(phoneRegex)]],

        });

        this.slideTwoForm = this.formBuilder.group({
            houseNo: [''],
            streetName:[''],
            city: [''],
            zipCode: [''],
            comments: ['']

        })



    }

    next(){
        this.slides.lockSwipes(false);
        this.profileSlider.slideNext();
        this.slides.lockSwipes(true);
    }



    prev(){
        this.slides.lockSwipes(false)
        this.profileSlider.slideNext();

    }

    save(){
        this.submitAttempt = true;

        if(!this.slideOneForm.valid){
            this.profileSlider.slideTo(0);
        }
        else if(!this.slideTwoForm.valid){
            this.profileSlider.slideTo(1);
        }
        else {
            console.log("success!")
            console.log(this.slideOneForm.value);
            console.log(this.slideTwoForm.value);
        }

    }


    ionViewWillEnter(){



    }

    public dismiss(): void {
        this.view.dismiss();
    }

}

#6

I think I solved the error, it was due to the fact that I was trying to init it inside the constructor, hence by that time it was not loaded so throwing above error.

ionViewDidLoad() {
this.slides.doSomething()
}