Couldn't use options property of ion-slides - ionic-framework

I have created a new app using Ionic v4 and tried adding slides to my app but I get an error stating
Can't bind to 'options' since it isn't a known property of 'ion-slides'
The html is
<ion-content padding>
<ion-slides [options]="slideOpts">
<ion-slide>
<h1>Slide 1</h1>
</ion-slide>
<ion-slide>
<h1>Slide 2</h1>
</ion-slide>
<ion-slide>
<h1>Slide 3</h1>
</ion-slide>
</ion-slides>
</ion-content>
My Ts is
import { Component,ViewChild } from '#angular/core';
import { NavController } from 'ionic-angular';
#Component({
selector: 'page-home',
templateUrl: 'home.html'
})
export class HomePage {
slideOpts = {
initialSlide: 1,
speed: 400
};
constructor(public navCtrl: NavController) {
}
}
However the same worked for me in Ionic v3. Could anyone please help me out?

Try this.. its working fine ionic 4.0.0
import { IonSlides } from '#ionic/angular';
#Component({
selector: 'page-home',
templateUrl: 'home.html'
})
export class HomePage {
#ViewChild(IonSlides) slides: IonSlides;
slideOpts = {
initialSlide: 1,
speed: 400
};
constructor(public navCtrl: NavController) {
}
ngOnInit() { this.slideOpts = {
initialSlide: 1,
speed: 400
};
}
}

Just laying my point here, especially for new people like me, so i'll try to go slow.
Assuming SlideComponent is an independant component like Directory
You already have a components.module.ts to export all components created in the components folder.
Here's how components.module.ts will look like:
import { NgModule } from '#angular/core';
import { CommonModule } from '#angular/common';
import { SlidesComponent } from './slides/slides.component';
import { IonicModule } from '#ionic/angular'; //import
#NgModule({
declarations: [SlidesComponent,],
exports:[SlidesComponent, /*feel free to add any additional component*/],
imports: [
CommonModule,
IonicModule //add
]
})
export class ComponentsModule { }
PS: this works on Ionic V 6.5

Related

Ionic Framework 3 Error: Window Redirect Problems

I'm new in Ionic Framework, and I'm using version 3 to build a simple application that redirects the user to an .html page after logging in. I've edited the home.ts file to make the log in possible, and I've built a test .html called index.html, in the folder "pages/home" inside the ionic project, but I'm getting an error when I try to conned the "submit" button to this index.html page:
Code in home.html
<ion-header>
<ion-navbar>
<ion-title>
Login
</ion-title>
</ion-navbar>
</ion-header>
<ion-content padding>
<ion-list no-lines>
<ion-item>
<ion-label floating>User</ion-label>
<ion-input type="text" [(ngModel)]="username"></ion-input>
</ion-item>
<ion-item>
<ion-label floating>Senha</ion-label>
<ion-input type="text" [(ngModel)]="password"></ion-input>
</ion-item>
<button block ion-button block (click)="signIn()">Sign in</button>
</ion-list>
</ion-content>
Code in home.ts
import { Component } from '#angular/core';
import { NavController, AlertController, IonicPage } from 'ionic-angular';
import { index } from 'c:/Ionic/task-1/src/pages/home/index.html';
#Component({
selector: 'page-home',
templateUrl: 'home.html'
})
export class HomePage {
public username : any = '';
public password : any = '';
constructor(public navCtrl: NavController, public alertCtrl: AlertController)
{
}
signIn() {
this.navCtrl.push('index.html');
}
}
The code in index.html
<ion-header>
<ion-navbar>
<ion-title>
Login
</ion-title>
</ion-navbar>
</ion-header>
<ion-content padding>
<p>Testing HTML page redirect</p>
</ion-list>
</ion-content>
The error: https://i.stack.imgur.com/vRivh.png
What could I do?
In ionic 3 you can navigate through pages using NavController.You should create a component that you want to route.
For that you have to import the component(page)
HTML file
<button block ion-button block (click)="signIn()">Sign in</button>
TS file
import { NavController } from 'ionic-angular';
import { StartPage } from './start-page';
#Component(
selector: 'app-home',
templateUrl: 'home.html'
})
class HomePage {
constructor(public navCtrl: NavController){}
signIn() {
this.navCtrl.push(StartPage);
}
}
Refer NavController documentation in ionic
check here
In home.ts file :
import { Component } from '#angular/core';
import { NavController, AlertController, IonicPage } from 'ionic-angular';
import { IndexPage} from '../index/index';
#Component({
selector: 'page-home',
templateUrl: 'home.html'
})
export class HomePage {
public username : any = '';
public password : any = '';
constructor(public navCtrl: NavController, public alertCtrl: AlertController){}
signIn() {
this.navCtrl.push(IndexPage);
}
}

Ionic signature-pad

I have install 'angular2-signaturepad' in my ionic project, and I created a test app and that's working fine, But when I try to integrate with my existing project shows me 'signature-pad' is not a known element' and '
<ion-content padding>
<signature-pad [ERROR ->][options]="signaturePadOptions"
(onBeginEvent)="drawStart()" (onEndEvent)="drawComplete()"></signatur"):
ng:///SignPageModule/SignPage.html#10:16
'signature-pad' is not a known element:
1. If 'signature-pad' is an Angular component, then verify that it is part of this module.
2. If 'signature-pad' is a Web Component then add 'CUSTOM_ELEMENTS_SCHEMA' to the '#NgModule.schemas' of this component to suppress this message. ("
<ion-content padding>
[ERROR ->]<signature-pad [options]="signaturePadOptions" (onBeginEvent)="drawStart()" (onEndEvent)="drawComplet"): ng:///SignPageModule/SignPage.html#10:1
Error: Template parse errors:
Can't bind to 'options' since it isn't a known property of 'signature-pad'.
1. If 'signature-pad' is an Angular component and it has 'options' input, then verify that it is part of this module.
2. If 'signature-pad' is a Web Component then add 'CUSTOM_ELEMENTS_SCHEMA' to the '#NgModule.schemas' of this component to suppress this message.
3. To allow any property add 'NO_ERRORS_SCHEMA' to the '#NgModule.schemas' of this component
This is the error I m facing. I was added 'CUSTOM_ELEMENTS_SCHEMA, NO_ERRORS_SCHEMA' in my app.module.ts file.
This is my sign.html code:
<ion-header>
<ion-navbar>
<ion-title>sign</ion-title>
</ion-navbar>
</ion-header>
<ion-content padding>
<ion-row [ngClass]="{'drawing-active': isDrawing}">
<ion-col></ion-col>
<ion-col style="border: 1px solid #5d6691;">
<signature-pad [options]="signaturePadOptions" (onBeginEvent)="drawStart()" (onEndEvent)="drawComplete()" style="width: 50px; height: 580px; color: red;"> </signature-pad>
</ion-col>
<ion-col></ion-col>
</ion-row>
<ion-row>
<ion-col>
<button ion-button style="color: #fff; background: #e59c9c;" (click)="clearPad()">Clear</button>
</ion-col>
<ion-col>
<button ion-button style="color: #fff; background: #4355a5;" (click)="savePad()">Save</button>
</ion-col>
<ion-col>
<button ion-button style="color: #fff; background: #e59c9c;" (click)="delPad()">delete</button>
</ion-col>
</ion-row>
<ion-row text-center>
<ion-col width-120>
<img [src]="signature" [hidden]= "signature == '' || signature == undefined " style="height: 200px;" />
</ion-col>
</ion-row>
This is my sign.ts code:
import { Component, ViewChild } from '#angular/core';
import { IonicPage, NavController, NavParams, ToastController } from 'ionic-angular';
import { SignaturePad } from 'angular2-signaturepad/signature-pad';
import { Storage } from '#ionic/storage';
#IonicPage()
#Component({
selector: 'page-sign',
templateUrl: 'sign.html',
})
export class SignPage {
public signature = '';
isDrawing = false;
#ViewChild(SignaturePad) signaturePad: SignaturePad;
private signaturePadOptions: Object = {
'minWidth': 1,
'canvasWidth': 320,
'canvasHeight': 200,
'backgroundColor': '#f6fbff',
'penColor': '#06219b'
};
constructor(public navCtrl: NavController,
public navParams: NavParams,
public storage: Storage,
public toastCtrl: ToastController ) {
}
ionViewDidLoad() {
this.signaturePad.clear()
this.storage.get('savedSignature').then((data) => {
this.signature = data;
});
}
drawComplete() {
this.isDrawing = false;
}
drawStart() {
this.isDrawing = true;
}
savePad() {
this.signature = this.signaturePad.toDataURL();
this.storage.set('savedSignature', this.signature);
this.signaturePad.clear();
let toast = this.toastCtrl.create({
message: 'New Signature saved.',
cssClass: 'homeToast',
duration: 3000,
position: 'top'
});
toast.present();
}
clearPad() {
this.signaturePad.clear();
}
delPad(){
this.storage.clear();
this.signature = '';
}
}
This is my app.module.ts code:
import { BrowserModule } from '#angular/platform-browser';
import { ErrorHandler, NgModule, CUSTOM_ELEMENTS_SCHEMA, NO_ERRORS_SCHEMA } from '#angular/core';
import { IonicApp, IonicErrorHandler, IonicModule } from 'ionic-angular';
import { SplashScreen } from '#ionic-native/splash-screen';
import { StatusBar } from '#ionic-native/status-bar';
import { MyApp } from './app.component';
import { HomePage } from '../pages/home/home';
import { SignaturePadModule } from 'angular2-signaturepad';
import { IonicStorageModule } from '#ionic/storage';
#NgModule({
declarations: [
MyApp,
HomePage
],
imports: [
BrowserModule,
IonicModule.forRoot(MyApp,{
backButtonText: '',
autoFocusAssist: true }),
SignaturePadModule,
IonicStorageModule.forRoot()
],
bootstrap: [IonicApp],
entryComponents: [
MyApp,
HomePage
],
providers: [
StatusBar,
SplashScreen,
{provide: ErrorHandler, useClass: IonicErrorHandler}
],
schemas: [ CUSTOM_ELEMENTS_SCHEMA, NO_ERRORS_SCHEMA ]
})
export class AppModule {}
I expected signature-pad to be working fine
Make sure to also import the module in sign.module.ts
import { SignaturePadModule } from 'angular2-signaturepad';
#NgModule({
imports: [
...
SignaturePadModule
],
declarations: [SignPage]
})
export class SignPageModule {}

Ionic 4 background blinks and tap delay

This is my first application using ionic4 and there is something weird happening. When I tap on any link, there is delay and the entire background blinks before it loads the page. Here is a video showing this weird behave: https://youtu.be/NqoOMQYyr4k
For reference, here is the code for the pages:
On the global.scss i have this property to setup the background
ion-content {
--background: #000 url('./assets/images/main-bg.png') no-repeat center center / cover;
}
news.page.ts
import { News } from './news.model';
import { Component, OnInit } from '#angular/core';
import { NewsService } from '../services/news.service';
import { Router } from '#angular/router';
import { NavController } from '#ionic/angular';
#Component({
selector: 'app-news',
templateUrl: './news.page.html',
styleUrls: ['./news.page.scss'],
})
export class NewsPage implements OnInit {
news: any;
constructor(private newsService: NewsService, private router: Router, private navController: NavController) { }
ngOnInit() {
this.news = this.newsService.getAllEvents();
}
go(id: string) {
this.navController.navigateForward('news/' + id);
}
}
news.page.html
<ion-header>
<ion-toolbar color="grey">
<ion-buttons slot="start">
<ion-menu-button></ion-menu-button>
</ion-buttons>
<ion-title style="color: #524A4A!important">News</ion-title>
</ion-toolbar>
</ion-header>
<ion-content>
<ion-grid padding class="margin-logo-header">
<ion-row>
<div>
<h2>Noticias HD Friends</h2>
</div>
</ion-row>
</ion-grid>
<ion-card color="grey" *ngFor="let news of news | async">
<ion-nav-pop (click)="go(news.id)" >
<ion-img src="{{news.picture}}"></ion-img>
<ion-card-header>
<ion-card-title>{{ news.title }}</ion-card-title>
</ion-card-header>
<ion-card-content>
<p>{{ news.subtitle }}</p>
</ion-card-content>
</ion-nav-pop>
</ion-card>
</ion-content>
news.service.ts
import { Injectable } from '#angular/core';
import { AngularFireDatabase, AngularFireList } from '#angular/fire/database';
import { News } from '../news/news.model';
#Injectable({
providedIn: 'root'
})
export class NewsService {
NODE = 'news/';
news: AngularFireList<News[]>;
constructor(private db: AngularFireDatabase) { }
getAllEvents() {
const localNews = this.db.list(this.NODE);
return localNews.valueChanges();
}
getNews(id: string) {
return this.db.object(this.NODE + id);
}
}
Is this a bug because it's a beta or is this something I messed up?
Thanks guys
UPDATE 1
This seems to be a bug on ionic framework. As soon as I get something I'll post here for future reference.

Ionic 3: ion- auto-complete - How to pass different data other than autocomplete generated data

I have created an auto complete functionality in ionic 3 framework.
app.component.html
<form [formGroup]="myForm" (ngSubmit)="openModal()">
<div class="ion-form-group">
<ion-auto-complete [dataProvider]="ionAutoCompleteService"
[options]="{ placeholder : 'Search an Institution' }" formControlName="institution"
required>
</ion-auto-complete>
</div>
<button [disabled]="!myForm.valid" icon-left ion-button type="submit" block>
<ion-icon name="link"></ion-icon>
Link Institution
</button>
</form>
for this I also create the service provider as follow
import {AutoCompleteService} from 'ionic2-auto-complete';
import { Http } from '#angular/http';
import {Injectable} from "#angular/core";
import 'rxjs/add/operator/map'
#Injectable()
export class IonicAutoCompleteService implements AutoCompleteService {
labelAttribute = "name";
constructor(private http:Http) {
}
getResults(keyword:string) {
return this.http.get("https://aqueous-oasis-93790.herokuapp.com/institutions/search?name="+keyword)
.map(
result =>
{
console.log(result)
return result.json().institutions
.filter(item => item.name.toLowerCase().startsWith(keyword.toLowerCase()) )
});
}
}
this service provides me the name of institutions which are retrieve from the json file.
To access this service I just need to import the service in app.component.ts file
app.component.ts
import { Component } from '#angular/core';
import { IonicPage, NavController, NavParams, ModalController } from 'ionic-angular';
import { FormGroup, FormControl, Validators } from '#angular/forms';
import { IonicAutoCompleteService } from '../../../services/ionic-autocomplete.service';
import { AddAccountModalPage } from './add-account-modal/add-account-modal';
#IonicPage()
#Component({
selector: 'page-add-account',
templateUrl: 'add-account.html',
})
export class AddAccountPage {
constructor(public navCtrl: NavController, public navParams: NavParams,
public ionAutoCompleteService:IonicAutoCompleteService,
public modalCtrl:ModalController) {
}
ngOnInit(): void { }
myForm = new FormGroup({
institution: new FormControl('', [Validators.required])
})
submit(): void {
console.log(this.myForm.value.institution)
}
onClick() {
console.log("img clicked")
}
openModal() {
let modal = this.modalCtrl.create(AddAccountModalPage);
modal.present();
}
}
My question is that, When I am submit the form, the value in search box will be submitted which is name of institution.
I want to send the institution name to following ionic modal
I also want to send institution id as a modal parameter like (ngSubmit)="openmodal(institution_id)" in app.component.html file
modal.html
<ion-header>
<ion-toolbar>
<ion-title>
Add Account Modal
</ion-title>
<ion-buttons start>
<button ion-button (click)="dismiss()">
<span ion-text color="primary" showWhen="ios">Cancel</span>
<ion-icon name="md-close" showWhen="android,windows"></ion-icon>
</button>
</ion-buttons>
</ion-toolbar>
</ion-header>
modal.ts
import { Component } from '#angular/core';
import { IonicPage, NavController, NavParams, ViewController } from 'ionic-angular';
#IonicPage()
#Component({
selector: 'page-add-account-modal',
templateUrl: 'add-account-modal.html',
})
export class AddAccountModalPage {
institution = "india"
constructor(public navCtrl: NavController, public navParams: NavParams,
public viewCtrl: ViewController) {
}
ionViewDidLoad() {
}
dismiss() {
this.viewCtrl.dismiss();
}
}
You can send parameters like this:
openModal() {
let Modal = this.modalCtrl.create(AddAccountModalPage,
{ institution: this.formGroup.get('institution').value
});
Modal.present();
}
and after get this parameter in modal.ts:
institution: any;
constructor(public navCtrl: NavController,
public navParams: NavParams,
public viewCtrl: ViewController) {
}
ngOnInit() {
this.institution= this.navParams.get('institution');
}

Ionic Pages - changing content

app.html
<ion-header>
<ion-navbar>
<ion-title>Blabla</ion-title>
<button ion-button color="primary" (click)="home()">Home</button>
<button ion-button color="primary" (click)="second()">Second</button>
</ion-navbar>
</ion-header>
<ion-content>
</ion-content>
<ion-nav #myNav [root]="rootPage"></ion-nav>
app.component.ts
import { Component, ViewChild } from '#angular/core';
import { Platform, NavController } from 'ionic-angular';
import { StatusBar } from '#ionic-native/status-bar';
import { SplashScreen } from '#ionic-native/splash-screen';
import { HomePage } from '../pages/home/home';
import { SecondpagePage } from '../pages/secondpage/secondpage';
#Component({
templateUrl: 'app.html'
})
export class MyApp {
#ViewChild('myNav') nav: NavController;
rootPage:any = HomePage;
constructor(platform: Platform, statusBar: StatusBar, splashScreen: SplashScreen) {
platform.ready().then(() => {
// Okay, so the platform is ready and our plugins are available.
// Here you can do any higher level native things you might need.
statusBar.styleDefault();
splashScreen.hide();
});
}
home() {
this.nav.setRoot(HomePage);
}
second() {
this.nav.setRoot(SecondpagePage);
}
}
In HomePage and SecondPage I put only <ion-content>Test1</ion-content> and <ion-content>Test2</ion-content>.
Now I have that situation - the header "covers" the rest. So I don't see any text because it's below the header. How can I change that behaviour?
And also I want to use one static immovable header/navbar (because there would be an animation). So content which can be changed is under that header/navbar.
Try moving the ion-nav into the ion-content, that should make it behave correctly.