Hi, I am trying to make a button that dynamically changes the font size of an app. My button works for my current page but i’m trying to update other pages as well. I tried passing the data but that doesn’t seem to be working. Can someone please suggest a solution. Thanks in advance!
Settings.html
<!--
Generated template for the SettingsPage page.
See http://ionicframework.com/docs/components/#navigation for more info on
Ionic pages and navigation.
Settings.html
-->
<ion-header>
<ion-navbar>
<ion-title>Settings</ion-title>
</ion-navbar>
</ion-header>
<ion-content padding [ngStyle]="{'font-size': fontSize+'em' }" id="page">
<div id="fonttable">
<p>Choose a Font Size</p>
<ion-buttons>
<button (click)="fontSizeChange(-0.2)" ion-button icon-only>
<ion-icon name="remove"></ion-icon>
</button>
<button (click)="fontSizeChange(0.2)" ion-button icon-only>
<ion-icon name="add"></ion-icon>
</button>
</ion-buttons>
</div>
</ion-content>
Settings.ts
import { Component } from '@angular/core';
import {App, IonicPage, NavController} from 'ionic-angular';
import { SettingsProvider } from './../../providers/settings/settings';
import {StudentHomePage} from "../StudentHome/StudentHome";
/**
* Generated class for the SettingsPage page.
*
* See https://ionicframework.com/docs/components/#navigation for more info on
* Ionic pages and navigation.
*/
@IonicPage()
@Component({
selector: 'page-StudentSettigns',
templateUrl: 'StudentSettigns.html',
})
export class StudentSettignsPage {
constructor(public navCtrl: NavController, public app: App, private settings: SettingsProvider) {
this.navCtrl.push(StudentHomePage, {
param1: this.fontSize
});
}
ionViewDidLoad() {
console.log('ionViewDidLoad SettingsPage');
}
fontSize: number = 1.5; // default font size in `em`
fontSizeChange($val: number){
this.fontSize +=$val;
}
}
StudentHome.html
<ion-header>
<ion-navbar>
<ion-title>Home</ion-title>
</ion-navbar>
</ion-header>
<ion-content padding [ngStyle]="{'font-size': fontSize+'em' }" id="page">
<h2>Welcome!</h2>
</ion-content>
StudentHome.ts
import { Component } from '@angular/core';
import { NavController } from 'ionic-angular';
import { NavParams } from "ionic-angular";
import { GamePage } from "../game/game";
@Component({
selector: 'page-home',
templateUrl: 'StudentHome.html'
})
export class StudentHomePage {
private fontSize: any;
constructor(public navCtrl: NavController, public navParams: NavParams) {
this.fontSize = navParams.get('param1');
}
}