The Config service 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.

Usage

Global

Basic example

  1. import { IonicModule } from '@ionic/angular';
  2. @NgModule({
  3. ...
  4. imports: [
  5. BrowserModule,
  6. IonicModule.forRoot({
  7. rippleEffect: false,
  8. mode: 'md'
  9. }),
  10. AppRoutingModule
  11. ],
  12. ...
  13. })


In the above example, we are disabling the Material Design ripple effect across the app, as well as forcing the mode to be Material Design.

Customizing Animations

  1. import { IonicModule } from '@ionic/angular';
  2. @NgModule({
  3. ...
  4. imports: [
  5. BrowserModule,
  6. IonicModule.forRoot({
  7. toastEnter: (AnimationC: Animation, baseEl: ShadowRoot, position: string): Promise<Animation> => {
  8. const baseAnimation = new AnimationC();
  9. const wrapperAnimation = new AnimationC();
  10. const hostEl = (baseEl.host || baseEl) as HTMLElement;
  11. const wrapperEl = baseEl.querySelector('.toast-wrapper') as HTMLElement;
  12. wrapperAnimation.addElement(wrapperEl);
  13. const bottom = `calc(8px + var(--ion-safe-area-bottom, 0px))`;
  14. const top = `calc(8px + var(--ion-safe-area-top, 0px))`;
  15. switch (position) {
  16. case 'top':
  17. wrapperEl.style.top = top;
  18. wrapperEl.style.opacity = 1;
  19. wrapperAnimation.fromTo('transform', `translateY(-${hostEl.clientHeight}px)`, 'translateY(10px)')
  20. break;
  21. case 'middle':
  22. const topPosition = Math.floor(
  23. hostEl.clientHeight / 2 - wrapperEl.clientHeight / 2
  24. );
  25. wrapperEl.style.top = `${topPosition}px`;
  26. wrapperAnimation.fromTo('opacity', 0.01, 1);
  27. break;
  28. default:
  29. wrapperEl.style.bottom = bottom;
  30. wrapperAnimation.fromTo('opacity', 0.01, 1);
  31. break;
  32. }
  33. return Promise.resolve(baseAnimation
  34. .addElement(hostEl)
  35. .easing('cubic-bezier(.36,.66,.04,1)')
  36. .duration(400)
  37. .add(wrapperAnimation));
  38. },
  39. }),
  40. AppRoutingModule
  41. ],
  42. ...
  43. })


In the above example, we are customizing the "enter" animation for the ion-toast component. When an ion-toast component is presented from the top, it will slide down instead of fading in.

By Component

Basic Example

  1. import { Component } from '@angular/core';
  2. import { Config } from '@ionic/angular';
  3. @Component({...})
  4. export class HomePage {
  5. constructor(private config: Config) {
  6. const text = this.config.get('backButtonText');
  7. this.config.set('backButtonIcon', 'home');
  8. }
  9. }

Config Options

Below is a list of config options that Ionic uses.

ConfigTypeDescription
actionSheetEnterAnimationBuilderProvides a custom enter animation for all ion-action-sheet, overriding the default "animation".
actionSheetLeaveAnimationBuilderProvides a custom leave animation for all ion-action-sheet, overriding the default "animation".
alertEnterAnimationBuilderProvides a custom enter animation for all ion-alert, overriding the default "animation".
alertLeaveAnimationBuilderProvides a custom leave animation for all ion-alert, overriding the default "animation".
animatedbooleanIf true, Ionic will enable all animations and transitions across the app.
backButtonIconstringOverrides the default icon in all <ion-back-button> components.
backButtonTextstringOverrides the default text in all <ion-back-button> components.
hardwareBackButtonbooleanIf true, Ionic will respond to the hardware back button in an Android device.
infiniteLoadingSpinnerSpinnerTypesOverrides the default spinner type in all <ion-infinite-scroll-content> components.
loadingEnterAnimationBuilderProvides a custom enter animation for all ion-loading, overriding the default "animation".
loadingLeaveAnimationBuilderProvides a custom leave animation for all ion-loading, overriding the default "animation".
loadingSpinnerSpinnerTypesOverrides the default spinner for all ion-loading overlays.
menuIconstringOverrides the default icon in all <ion-menu-button> components.
menuTypestringOverrides the default menu type for all <ion-menu> components.
modalEnterAnimationBuilderProvides a custom enter animation for all ion-modal, overriding the default "animation".
modalLeaveAnimationBuilderProvides a custom leave animation for all ion-modal, overriding the default "animation".
modeModeThe mode determines which platform styles to use for the whole application.
navAnimationAnimationBuilderOverrides the default "animation" of all ion-nav and ion-router-outlet across the whole application.
pickerEnterAnimationBuilderProvides a custom enter animation for all ion-picker, overriding the default "animation".
pickerLeaveAnimationBuilderProvides a custom leave animation for all ion-picker, overriding the default "animation".
popoverEnterAnimationBuilderProvides a custom enter animation for all ion-popover, overriding the default "animation".
popoverLeaveAnimationBuilderProvides a custom leave animation for all ion-popover, overriding the default "animation".
refreshingIconstringOverrides the default icon in all <ion-refresh-content> components.
refreshingSpinnerSpinnerTypesOverrides the default spinner type in all <ion-refresh-content> components.
spinnerSpinnerTypesOverrides the default spinner in all <ion-spinner> components.
statusTapbooleanIf true, clicking or tapping the status bar will cause the content to scroll to the top.
swipeBackEnabledbooleanIf true, Ionic will enable the "swipe-to-go-back" gesture across the application.
tabButtonLayoutTabButtonLayoutOverrides the default "layout" of all ion-bar-button across the whole application.
toastEnterAnimationBuilderProvides a custom enter animation for all ion-toast, overriding the default "animation".
toastLeaveAnimationBuilderProvides a custom leave animation for all ion-toast, overriding the default "animation".