Skip to main content
Version: v8

Config

Ionic Config は、アプリ全体でコンポーネントのプロパティをグローバルに変更する方法を提供します。アプリモード、タブボタンのレイアウト、アニメーションなどを設定できます。

グローバル設定

利用可能な設定キーは、IonicConfigインターフェースで見つけることができます。

次の例では、リップル効果を無効にし、モードを Material Design にデフォルト設定します:

example.js
window.Ionic = {
config: {
rippleEffect: false,
mode: 'md',
},
};

コンポーネントごとの設定

Ionic Config はリアクティブではありません。コンポーネントがレンダリングされた後に設定の値を更新しても、以前の値のままになります。リアクティブな値が必要な場合は、設定を更新する代わりに、コンポーネントのプロパティを使用することをお勧めします。

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>

プラットフォームごとの設定

Ionic Config は、プラットフォームごとに設定することもできます。たとえば、これにより、潜在的に遅いデバイスのブラウザでアプリが実行されている場合にアニメーションを無効にできます。開発者は、Platform ユーティリティを活用してこれを実現できます。

次の例では、モバイル Web ブラウザでアプリが実行されている場合にのみ、Ionic アプリのすべてのアニメーションを無効にしています。

note

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.

app.module.ts
import { isPlatform, IonicModule } from '@ionic/angular';

@NgModule({
...
imports: [
IonicModule.forRoot({
animated: !isPlatform('mobileweb')
})
],
...
})

フォールバック

次の例では、プラットフォームに基づいて完全に異なる設定を設定でき、プラットフォームが一致しない場合はデフォルト設定にフォールバックします:

app.module.ts
import { isPlatform, IonicModule } from '@ionic/angular';

const getConfig = () => {
let config = {
animated: false
};

if (isPlatform('iphone')) {
config = {
...config,
backButtonText: 'Previous'
}
}

return config;
}
@NgModule({
...
imports: [
IonicModule.forRoot(getConfig())
],
...
});

オーバーライド

この最後の例では、異なるプラットフォーム要件に基づいて設定オブジェクトを累積できます。

app.module.ts
import { isPlatform, IonicModule } from '@ionic/angular';

const getConfig = () => {
if (isPlatform('hybrid')) {
return {
tabButtonLayout: 'label-hide'
}
}

return {
tabButtonLayout: 'icon-top'
};
}
@NgModule({
...
imports: [
IonicModule.forRoot(getConfig())
],
...
});

モードへのアクセス

場合によっては、アプリケーションロジック内で現在の Ionic モードにプログラム的にアクセスする必要があるかもしれません。これは、条件付き動作を適用したり、特定のアセットを取得したり、アクティブなスタイリングモードに基づいて他のアクションを実行したりするのに役立ちます。

設定の読み取り(Angular)

Ionic Angular は、Ionic Config にアクセスするためのConfigプロバイダーを提供します。

get

説明設定値をanyとして返します。設定が定義されていない場合はnullを返します。
シグネチャget(key: string, fallback?: any) => any

import { Config } from '@ionic/angular';

@Component(...)
class AppComponent {
constructor(config: Config) {
const mode = config.get('mode');
}
}

getBoolean

説明設定値をbooleanとして返します。設定が定義されていない場合はfalseを返します。
シグネチャgetBoolean(key: string, fallback?: boolean) => boolean

import { Config } from '@ionic/angular';

@Component(...)
class AppComponent {
constructor(config: Config) {
const swipeBackEnabled = config.getBoolean('swipeBackEnabled');
}
}

getNumber

説明設定値をnumberとして返します。設定が定義されていない場合は0を返します。
シグネチャgetNumber(key: string, fallback?: number) => number

インターフェース

IonicConfig

以下は、Ionic が使用する設定オプションです。

ConfigType説明
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.
backButtonDefaultHrefstringOverrides the default value for the defaultHref property in all <ion-back-button> components.
backButtonIconstringOverrides the default icon in all <ion-back-button> components.
backButtonTextstringOverrides the default text in all <ion-back-button> components.
innerHTMLTemplatesEnabledbooleanRelevant Components: ion-alert, ion-infinite-scroll-content, ion-loading, ion-refresher-content, ion-toast. If true, content passed to the relevant components will be parsed as HTML instead of plaintext. Defaults to false.
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.
logLevel'OFF' | 'ERROR' | 'WARN'Configures the logging level for Ionic Framework. If 'OFF', no errors or warnings are logged. If 'ERROR', only errors are logged. If 'WARN', errors and warnings are logged.
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".
platformPlatformConfigOverrides the default platform detection methods.
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.
rippleEffectbooleanIf true, Material Design ripple effects will be enabled across the app.
sanitizerEnabledbooleanIf true, Ionic will enable a basic DOM sanitizer on component properties that accept custom HTML.
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.
toastDurationnumberOverrides the default duration for all ion-toast components.
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".
toggleOnOffLabelsbooleanOverrides the default enableOnOffLabels in all ion-toggle components.
experimentalCloseWatcherbooleanExperimental: If true, the CloseWatcher API will be used to handle all Escape key and hardware back button presses to dismiss menus and overlays and to navigate. Note that the hardwareBackButton config option must also be true.
focusManagerPriorityFocusManagerPriority[]Experimental: When defined, Ionic will move focus to the appropriate element after each page transition. This ensures that users relying on assistive technology are informed when a page transition happens. Disabled by default.