Config

配置允许您配置整个应用程序或特定平台。 您可以在此处设置标签位置,图标模式,动画等。

import { IonicApp, IonicModule } from 'ionic-angular';

@NgModule({
  declarations: [ MyApp ],
  imports: [
    BrowserModule,
    IonicModule.forRoot(MyApp, {
      backButtonText: 'Go Back',
      iconMode: 'ios',
      modalEnter: 'modal-slide-in',
      modalLeave: 'modal-slide-out',
      tabsPlacement: 'bottom',
      pageTransition: 'ios-transition'
    }, {}
  )],
  bootstrap: [IonicApp],
  entryComponents: [ MyApp ],
  providers: []
})

配置可以在多个级别覆盖,允许更细粒度的配置。 以下是一个应用程序可以根据平台覆盖我们想要的任何设置的示例。

import { IonicModule } from 'ionic-angular';

@NgModule({
  ...
  imports: [
    BrowserModule,
    IonicModule.forRoot(MyApp, {
      tabsPlacement: 'bottom',
      platforms: {
        ios: {
          tabsPlacement: 'top',
        }
      }
    }, {}
  )],
  ...
})

效果:

我们也可以在组件级配置这些值。 选择 tabsPlacement,我们可以将其配置为 ion-tabs 上的属性。

<ion-tabs tabsPlacement="top">
  <ion-tab tabTitle="Dash" tabIcon="pulse" [root]="tabRoot"></ion-tab>
</ion-tabs>

我们可以配置的最后一个方法是通过URL查询字符串。 这对于在浏览器中进行测试非常有用。 简单地向网址添加?ionic<PROPERTYNAME>=<value>

http://localhost:8100/?ionicTabsPlacement=bottom

任何值都可以添加到配置文件中,并在后面查看任何组件。

config.set('ios', 'favoriteColor', 'green');

// from any page in your app:
config.get('favoriteColor'); // 'green' when iOS

配置值可以来自任何地方,并且是任何东西,但每个模式都有默认值。 主题文档具有默认模式配置的图表。 以下图表显示每个属性,并说明其控件的内容。

Config Property Type Details
activator string Used for buttons, changes the effect of pressing on a button. Available options:"ripple","highlight".
actionSheetEnter string The name of the transition to use while an action sheet is presented.
actionSheetLeave string The name of the transition to use while an action sheet is dismissed.
alertEnter string The name of the transition to use while an alert is presented.
alertLeave string The name of the transition to use while an alert is dismissed.
backButtonText string The text to display by the back button icon in the navbar.
backButtonIcon string The icon to use as the back button icon.
iconMode string The mode to use for all icons throughout the application. Available options:"ios","md"
locationStrategy string Set to 'path' to remove hashbangs when using Deeplinking.
loadingEnter string The name of the transition to use while a loading indicator is presented.
loadingLeave string The name of the transition to use while a loading indicator is dismissed.
menuType string Type of menu to display. Available options:"overlay","reveal","push".
modalEnter string The name of the transition to use while a modal is presented.
modalLeave string The name of the transition to use while a modal is dismiss.
mode string The mode to use throughout the application.
pageTransition string The name of the transition to use while changing pages. Available options:"ios-transition","md-transition","wp-transition".
pickerEnter string The name of the transition to use while a picker is presented.
pickerLeave string The name of the transition to use while a picker is dismissed.
popoverEnter string The name of the transition to use while a popover is presented.
popoverLeave string The name of the transition to use while a popover is dismissed.
spinner string The default spinner to use when a name is not defined.
swipeBackEnabled boolean Whether native iOS swipe to go back functionality is enabled.
tabsHighlight boolean Whether to show a highlight line under the tab when it is selected.
tabsLayout string The layout to use for all tabs. Available options:"icon-top","icon-left","icon-right","icon-bottom","icon-hide","title-hide".
tabsPlacement string The position of the tabs relative to the content. Available options:"top","bottom"
tabsHideOnSubPages boolean Whether to hide the tabs on child pages or not. Iftrueit will not show the tabs on child pages.
toastEnter string The name of the transition to use while a toast is presented.
toastLeave string The name of the transition to use while a toast is dismissed.

实例成员

get(key, fallbackValue)

返回一个单个的配置值, 通过Key.

Param Type Details
key string the key for the config valueOPTIONAL
fallbackValue any a fallback value to use when the config value was not found, or is config value isnull. Fallback value defaults tonull.OPTIONAL

getBoolean(key, fallbackValue)

相同于get(),但总是返回一个布尔值。 如果值get()为 null,那么它将返回thefallback 值(默认值为false)。 否则,如果配置值是真实的,getBoolean()将返回。 它也返回一个config值是字符串值“true”。

Param Type Details
key string the key for the config valueOPTIONAL
fallbackValue boolean a fallback value to use when the config value wasnull. Fallback value defaults tofalse.OPTIONAL

getNumber(key, fallbackValue)

与get()相同,但总是返回一个数字值。 对接收到的值fromget()使用parseFloat()。 如果解析的结果是NaN,那么它将返回传递给fallbackValue的值。 如果没有提供回退值,那么当结果不是有效的数字时,它将默认返回NaN。

Param Type Details
key string the key for the config valueOPTIONAL
fallbackValue number a fallback value to use when the config value turned out to beNaN. Fallback value defaults toNaN.OPTIONAL

set(platform, key, value)

设置单个配置值。

Param Type Details
platform string The platform (either 'ios' or 'android') that the config value should apply to. Leaving this blank will apply the config value to all platforms.OPTIONAL
key string The key used to look up the value at a later point in time.OPTIONAL
value string The config value being stored.OPTIONAL

results matching ""

    No results matching ""