Config
Ionic Config provides a way to change the properties of components globally across an app. It can set the app mode, tab button layout, animations, and more.
Global Config
The available config keys can be found in the IonicConfig
interface.
The following example disables ripple effects and default the mode to Material Design:
- JavaScript
- Angular
- Angular (Standalone)
- React
- Vue
window.Ionic = {
config: {
rippleEffect: false,
mode: 'md',
},
};
import { IonicModule } from '@ionic/angular';
@NgModule({
...
imports: [
IonicModule.forRoot({
rippleEffect: false,
mode: 'md'
})
],
...
})
import { provideIonicAngular } from '@ionic/angular/standalone';
bootstrapApplication(AppComponent, {
providers: [
...,
provideIonicAngular({
rippleEffect: false,
mode: 'md'
})
]
})
The setupIonicReact
function must be called before rendering any Ionic components (including IonApp
).
import { setupIonicReact } from '@ionic/react';
setupIonicReact({
rippleEffect: false,
mode: 'md',
});
import { IonicVue } from '@ionic/vue';
import { createApp } from 'vue';
createApp(App).use(IonicVue, {
rippleEffect: false,
mode: 'md',
});
Per-Component Config
Ionic Config is not reactive. Updating the config's value after the component has rendered will result in the previous value. It is recommended to use a component's properties instead of updating the config, when you require reactive values.
- JavaScript
- Angular
- Angular (Standalone)
- React
- Vue
Not recommended
window.Ionic = {
config: {
// Not recommended when your app requires reactive values
backButtonText: 'Go Back',
},
};
Recommended
<ion-back-button></ion-back-button>
<script>
const backButton = document.querySelector('ion-back-button');
/**
* The back button text can be updated
* anytime the locale changes.
*/
backButton.text = 'Go Back';
</script>
Not recommended
import { IonicModule } from '@ionic/angular';
@NgModule({
...
imports: [
IonicModule.forRoot({
// Not recommended when your app requires reactive values
backButtonText: 'Go Back'
})
],
...
});
Recommended
<ion-back-button [text]="backButtonText"></ion-back-button>
@Component(...)
class MyComponent {
/**
* The back button text can be updated
* anytime the locale changes.
*/
backButtonText = 'Go Back';
}
Not recommended
import { provideIonicAngular } from '@ionic/angular/standalone';
bootstrapApplication(AppComponent, {
providers: [
...,
provideIonicAngular({
// Not recommended when your app requires reactive values
backButtonText: 'Go Back'
})
]
})
Recommended
<ion-back-button [text]="backButtonText"></ion-back-button>
@Component(...)
class MyComponent {
/**
* The back button text can be updated
* anytime the locale changes.
*/
backButtonText = 'Go Back';
}
Not recommended
import { setupIonicReact } from '@ionic/react';
setupIonicReact({
// Not recommended when your app requires reactive values
backButtonText: 'Go Back',
});
Recommended
import { useState } from 'react';
import { IonBackButton } from '@ionic/react';
const ExampleComponent = () => {
const [backButtonText, setBackButtonText] = useState('Go Back');
return (
{/*
* The back button text can be updated
* anytime the locale changes.
*/}
<IonBackButton text={backButtonText}></IonBackButton>
)
}
Not recommended
import { IonicVue } from '@ionic/vue';
import { createApp } from 'vue';
// Not recommended when your app requires reactive values
createApp(App).use(IonicVue, {
backButtonText: 'Go Back',
});
Recommended
<template>
<ion-back-button [text]="backButtonText"></ion-back-button>
</template>
<script setup lang="ts">
import { IonBackButton } from '@ionic/vue';
import { ref } from 'vue';
/**
* The back button text can be updated
* anytime the locale changes.
*/
const backButtonText = ref('Go Back');
</script>
Per-Platform Config
Ionic Config can also be set on a per-platform basis. For example, this allows you to disable animations if the app is being run in a browser on a potentially slower device. Developers can take advantage of the Platform utilities to accomplish this.
In the following example, we are disabling all animations in our Ionic app only if the app is running in a mobile web browser.
- Angular
- Angular (Standalone)
- React
- Vue
Since the config is set at runtime, you will not have access to the Platform Dependency Injection. Instead, you can use the underlying functions that the provider uses directly.
See the Angular Platform Documentation for the types of platforms you can detect.
import { isPlatform, IonicModule } from '@ionic/angular';
@NgModule({
...
imports: [
IonicModule.forRoot({
animated: !isPlatform('mobileweb')
})
],
...
})
Since the config is set at runtime, you will not have access to the Platform Dependency Injection. Instead, you can use the underlying functions that the provider uses directly.
See the Angular Platform Documentation for the types of platforms you can detect.
import { isPlatform, provideIonicAngular } from '@ionic/angular/standalone';
bootstrapApplication(AppComponent, {
providers: [
...,
provideIonicAngular({
animated: !isPlatform('mobileweb')
})
]
})
See the React Platform Documentation for the types of platforms you can detect.
import { isPlatform, setupIonicReact } from '@ionic/react';
setupIonicReact({
animated: !isPlatform('mobileweb'),
});