警告框控制器

警报是一个对话框,向用户显示信息或使用输入收集用户的信息。 应用程式内容上方会显示快讯,使用者必须手动关闭快讯,才能恢复与应用程式的互动。 它还可以选择具有 title ,subTitle 和 message。

您可以在创建方法的第一个参数中传递所有警报的选项:create(opts)。 否则,警报的实例具有添加选项的方法,例如setTitle()或addButton()。

警告按钮

在 buttons 阵列中,每个按钮都包含其 text 的属性,以及可选的 handler。 如果处理程序返回false,那么当单击按钮时,该警报将不会自动被关闭。 所有按钮将按照从左到右添加到 buttons 阵列的顺序显示。 注意:最右边的按钮(阵列中的最后一个)是主按钮。

或者,role 属性可以添加到按钮,如 cancel。 如果其中一个按钮上有 cancel 角色,则如果通过点击背景来关闭警报,则会从具有取消角色的按钮中触发处理程序。

警告输入

警报还可以包括几个不同的输入,其数据可以传回应用程序。 输入可以作为提示用户提供信息的简单方法。 收音机,复选框和文本输入都被接受,但不能混合。 例如,警报可以具有所有单选按钮输入或所有复选框输入,但相同的警报不能混合无线电和复选框输入。 但请注意,不同类型的“文本”“输入可能会混合,如网址,电子邮件,文本等。如果您需要一个不符合警报指导原则的复杂表单UI,那么我们建议构建表单 在一个模态代替。

使用

constructor(private alertCtrl: AlertController) {

}

presentAlert() {
  let alert = this.alertCtrl.create({
    title: 'Low battery',
    subTitle: '10% of battery remaining',
    buttons: ['Dismiss']
  });
  alert.present();
}

presentConfirm() {
  let alert = this.alertCtrl.create({
    title: 'Confirm purchase',
    message: 'Do you want to buy this book?',
    buttons: [
      {
        text: 'Cancel',
        role: 'cancel',
        handler: () => {
          console.log('Cancel clicked');
        }
      },
      {
        text: 'Buy',
        handler: () => {
          console.log('Buy clicked');
        }
      }
    ]
  });
  alert.present();
}

presentPrompt() {
  let alert = this.alertCtrl.create({
    title: 'Login',
    inputs: [
      {
        name: 'username',
        placeholder: 'Username'
      },
      {
        name: 'password',
        placeholder: 'Password',
        type: 'password'
      }
    ],
    buttons: [
      {
        text: 'Cancel',
        role: 'cancel',
        handler: data => {
          console.log('Cancel clicked');
        }
      },
      {
        text: 'Login',
        handler: data => {
          if (User.isValid(data.username, data.password)) {
            // logged in!
          } else {
            // invalid login
            return false;
          }
        }
      }
    ]
  });
  alert.present();
}

效果:

静态成员

config

create(opts)

用标题,输入和按钮显示警报

参数 类型 详情
opts AlertOptions Alert. See the table below

高级

警告选项

属性 类型 描述
title string The title for the alert.
subTitle string The subtitle for the alert.
message string The message for the alert.
cssClass string Additional classes for custom styles, separated by spaces.
inputs array An array of inputs for the alert. See input options.
buttons array An array of buttons for the alert. See buttons options.
enableBackdropDismiss boolean Whether the alert should be dismissed by tapping the backdrop.

Input options

Property Type Description
type string The type the input should be: text, tel, number, etc.
name string The name for the input.
placeholder string The input's placeholder (for textual/numeric inputs)
value string The input's value.
label string The input's label (only for radio/checkbox inputs)
checked boolean Whether or not the input is checked.
id string The input's id.

按钮选项

属性 类型 描述
text string The buttons displayed text.
handler any Emitted when the button is pressed.
cssClass string An additional CSS class for the button.
role string The buttons role, null orcancel.

取消和异步导航

在关闭警报后,应用程序可能还需要根据处理程序的逻辑转换到另一个页面。 然而,由于在大致相同的时间触发了多个转换,导航控制器很难对可能异步启动的多个转换进行动画生成动画。 这在Nav Transition Promises部分进一步描述。 对于警报,这意味着最好先在同一导航控制器上开始新的转换之前等待警报完成转换。

在下面的示例中,在单击警报按钮后,其处理程序将等待异步操作完成,然后使用弹出窗口在同一个堆栈中返回页面。 潜在的问题是异常操作可能在警报甚至完成转换之前已经完成。 在这种情况下,最好先确保警报已完成过渡,然后开始下一个转换。

let alert = this.alertCtrl.create({
  title: 'Hello',
  buttons: [{
    text: 'Ok',
    handler: () => {
      // user has clicked the alert button
      // begin the alert's dismiss transition
      let navTransition = alert.dismiss();

      // start some async method
      someAsyncOperation().then(() => {
        // once the async operation has completed
        // then run the next nav transition after the
        // first transition has finished animating out

        navTransition.then(() => {
          this.nav.pop();
        });
      });
      return false;
    }
  }]
});

alert.present();

请注意,处理程序返回false。 按钮处理程序的一个功能是,当他们点击按钮时,他们会自动关闭警报,但是我们需要更多的关于转换的控制。 因为处理程序返回false,所以警报不会自动关闭。 相反,您现在可以完全控制警报完成转换的时间,以及在开始新的转换之前等待警报完成转换的能力。

Sass Variables

  • All

属性 默认值 描述
$alert-min-width 250px Minimum width of the alert
$alert-max-height 90% Maximum height of the alert
$alert-button-line-height 20px Line height of the alert button
$alert-button-font-size 14px Font size of the alert button
$alert-input-placeholder-color #999 Color of the alert input placeholder

Sass Variables

  • iOS

Property Default Description
$alert-ios-max-width 270px Max width of the alert
$alert-ios-border-radius 13px Border radius of the alert
$alert-ios-background #f8f8f8 Background color of the alert
$alert-ios-box-shadow none Box shadow of the alert
$alert-ios-head-padding 12px 16px 7px Padding of the alert head
$alert-ios-head-text-align center Text align of the alert head
$alert-ios-title-margin-top 8px Margin top of the alert title
$alert-ios-title-font-size 17px Font size of the alert title
$alert-ios-title-font-weight 600 Font weight of the alert title
$alert-ios-sub-title-font-size 14px Font size of the alert sub title
$alert-ios-sub-title-text-color #666 Text color of the alert sub title
$alert-ios-message-padding 0 16px 21px Padding of the alert message
$alert-ios-message-font-size 13px Font size of the alert message
$alert-ios-message-text-align center Text align of the alert message
$alert-ios-message-text-color inherit Text color of the alert message
$alert-ios-message-padding-empty 0 0 12px 0 Padding of the alert empty message
$alert-ios-content-max-height 240px Maximum height of the alert content
$alert-ios-input-margin-top 10px Margin top of the alert input
$alert-ios-input-padding 6px Padding on the alert input
$alert-ios-input-border-color #ccc Border color of the alert input
$alert-ios-input-border $hairlines-width solid $alert-ios-input-border-color Border of the alert input
$alert-ios-input-border-radius 4px Border radius of the alert input
$alert-ios-input-background-color #fff Background color of the alert input
$alert-ios-button-group-flex-wrap wrap Flex wrap of the alert button group
$alert-ios-button-flex 1 1 auto Flex of the alert button
$alert-ios-button-margin 0 Margin of the alert button
$alert-ios-button-min-width 50% Min width of the alert button
$alert-ios-button-min-height 44px Minimum height of the alert button
$alert-ios-button-font-size 17px Font size of the alert button
$alert-ios-button-text-color color($colors-ios, primary) Color of the text in the alert button
$alert-ios-button-background-color transparent Background color of the alert button
$alert-ios-button-background-color-activated #e9e9e9 Background color of the alert activated button
$alert-ios-button-border-width $hairlines-width Border width of the alert button
$alert-ios-button-border-style solid Border style of the alert button
$alert-ios-button-border-color #dbdbdf Border color of the alert button
$alert-ios-button-border-radius 0 Border radius of the alert button
$alert-ios-button-main-font-weight bold Font weight of the main text on the alert button
$alert-ios-list-border-top $alert-ios-button-border-width $alert-ios-button-border-style $alert-ios-button-border-color Border top of the alert list
$alert-ios-radio-label-padding 13px Padding on the label for the radio alert
$alert-ios-radio-label-text-color initial Text color of the label for the radio alert
$alert-ios-radio-label-text-color-checked $alert-ios-button-text-color Text color of the label for the checked radio alert
$alert-ios-radio-min-width 30px Min width of the radio alert
$alert-ios-radio-icon-top -7px Top of the icon in the radio alert
$alert-ios-radio-icon-left 7px Left of the icon in the radio alert
$alert-ios-radio-icon-width 6px Width of the icon in the radio alert
$alert-ios-radio-icon-height 12px Height of the icon in the radio alert
$alert-ios-radio-icon-border-width 2px Border width of the icon in the radio alert
$alert-ios-radio-icon-border-style solid Border style of the icon in the radio alert
$alert-ios-radio-icon-border-color $alert-ios-button-text-color Border color of the icon in the radio alert
$alert-ios-radio-icon-transform rotate(45deg) Transform of the icon in the radio alert
$alert-ios-checkbox-label-padding 13px Padding of the label for the checkbox in the alert
$alert-ios-checkbox-label-text-color initial Text color of the label for the checkbox in the alert
$alert-ios-checkbox-label-text-color-checked initial Text color of the label for the checked checkbox in the alert
$alert-ios-checkbox-margin 10px 6px 10px 16px Margin of the checkbox in the alert
$alert-ios-checkbox-size 21px Size of the checkbox in the alert
$alert-ios-checkbox-border-width $hairlines-width Border width of the checkbox in the alert
$alert-ios-checkbox-border-style solid Border style of the checkbox in the alert
$alert-ios-checkbox-border-radius 50% Border radius of the checkbox in the alert
$alert-ios-checkbox-border-color-off $list-ios-border-color Border color of the checkbox in the alert when off
$alert-ios-checkbox-border-color-on color($colors-ios, primary) Border color of the checkbox in the alert when on
$alert-ios-checkbox-background-color-off $list-ios-background-color Background color of the checkbox in the alert when off
$alert-ios-checkbox-background-color-on color($colors-ios, primary) Background color of the checkbox in the alert when on
$alert-ios-checkbox-icon-top 4px Top of the icon in the checkbox alert
$alert-ios-checkbox-icon-left 7px Left of the icon in the checkbox alert
$alert-ios-checkbox-icon-width 4px Width of the icon in the checkbox alert
$alert-ios-checkbox-icon-height 9px Height of the icon in the checkbox alert
$alert-ios-checkbox-icon-border-width $alert-ios-checkbox-border-width Border width of the icon in the checkbox alert
$alert-ios-checkbox-icon-border-style $alert-ios-checkbox-border-style Border style of the icon in the checkbox alert
$alert-ios-checkbox-icon-border-color $background-ios-color Border color of the icon in the checkbox alert
$alert-ios-checkbox-icon-transform rotate(45deg) Transform of the icon in the checkbox alert

Sass Variables

  • Material Design
属性 默认值 描述
$alert-md-max-width 280px Max width of the alert
$alert-md-border-radius 2px Border radius of the alert
$alert-md-background-color #fafafa Background color of the alert
$alert-md-box-shadow-color rgba(0, 0, 0, .4) Box shadow color of the alert
$alert-md-box-shadow 0 16px 20px $alert-md-box-shadow-color Box shadow of the alert
$alert-md-head-padding 24px 24px 20px 24px Padding of the alert head
$alert-md-head-text-align left Text align of the alert head
$alert-md-title-font-size 22px Font size of the alert title
$alert-md-sub-title-font-size 16px Font size of the alert sub title
$alert-md-message-padding 0 24px 24px 24px Padding of the alert message
$alert-md-message-font-size 15px Font size of the alert message
$alert-md-message-text-color rgba(0, 0, 0, .5) Text color of the alert message
$alert-md-message-padding-empty 0 Padding of the alert empty message
$alert-md-content-max-height 240px Maximum height of the alert content
$alert-md-input-border-width 1px Border width of the alert input
$alert-md-input-border-style solid Border style of the alert input
$alert-md-input-border-color #dedede Border color of the alert input
$alert-md-input-text-color #000 Text color of the alert input
$alert-md-input-border-width-focused 2px Border width of the alert input when focused
$alert-md-input-border-style-focused $alert-md-input-border-style Border style of the alert input when focused
$alert-md-input-border-color-focused color($colors-md, primary) Border color of the alert input when focused
$alert-md-input-margin-top 5px Margin top of the alert input
$alert-md-input-margin-right 0 Margin right of the alert input
$alert-md-input-margin-bottom 5px Margin bottom of the alert input
$alert-md-input-margin-left 0 Margin left of the alert input
$alert-md-button-group-flex-wrap wrap-reverse Flex wrap of the alert button group
$alert-md-button-group-padding 8px 8px 8px 24px Padding of the alert button group
$alert-md-button-group-justify-content flex-end Justify content of the alert button group
$alert-md-button-padding 10px Padding of the alert button
$alert-md-button-margin 0 8px 0 0 Margin of the alert button
$alert-md-button-font-weight 500 Font weight of the alert button
$alert-md-button-text-color color($colors-md, primary) Text color of the alert button
$alert-md-button-background-color transparent Background color of the alert button
$alert-md-button-background-color-activated rgba(158, 158, 158, .2) Background color of the alert activated button
$alert-md-button-border-radius 2px Border radius of the alert button
$alert-md-button-text-transform uppercase Text transform of the alert button
$alert-md-button-text-align right Text align of the alert button
$alert-md-list-border-top 1px solid $alert-md-input-border-color Border top of the alert list
$alert-md-list-border-bottom $alert-md-list-border-top Border bottom of the alert list
$alert-md-radio-label-padding 13px 26px Padding on the label for the radio alert
$alert-md-radio-label-text-color initial Text color of the label for the radio alert
$alert-md-radio-label-text-color-checked $alert-md-button-text-color Text color of the label for the checked radio alert
$alert-md-radio-top 0 Top of the alert radio
$alert-md-radio-left 13px Left of the alert radio
$alert-md-radio-width 16px Width of the alert radio
$alert-md-radio-height 16px Height of the alert radio
$alert-md-radio-border-width 2px Border width of the alert radio
$alert-md-radio-border-style solid Border style of the alert radio
$alert-md-radio-border-radius 50% Border radius of the alert radio
$alert-md-radio-border-color-off darken($list-md-border-color, 40%) Border color of the alert radio when off
$alert-md-radio-border-color-on $alert-md-button-text-color Border color of the alert radio when on
$alert-md-radio-icon-top 2px Top of the icon in the alert radio
$alert-md-radio-icon-left 2px Left of the icon in the alert radio
$alert-md-radio-icon-width 8px Width of the icon in the alert radio
$alert-md-radio-icon-height 8px Height of the icon in the alert radio
$alert-md-radio-icon-border-radius $alert-md-radio-border-radius Border radius of the icon in the alert radio
$alert-md-radio-icon-transform-off scale3d(0, 0, 0) Transform of the icon in the alert radio when off
$alert-md-radio-icon-transform-on scale3d(1, 1, 1) Transform of the icon in the alert radio when on
$alert-md-radio-icon-transition transform 280ms cubic-bezier(.4, 0, .2, 1) Transition of the icon in the alert radio
$alert-md-checkbox-label-padding 13px 26px Padding of the label for the checkbox in the alert
$alert-md-checkbox-label-text-color initial Text color of the label for the checkbox in the alert
$alert-md-checkbox-label-text-color-checked initial Text color of the label for the checked checkbox in the alert
$alert-md-checkbox-top 0 Top of the checkbox in the alert
$alert-md-checkbox-left 13px Left of the checkbox in the alert
$alert-md-checkbox-width 16px Width of the checkbox in the alert
$alert-md-checkbox-height 16px Height of the checkbox in the alert
$alert-md-checkbox-border-width 2px Border width of the checkbox in the alert
$alert-md-checkbox-border-style solid Border style of the checkbox in the alert
$alert-md-checkbox-border-radius 2px Border radius of the checkbox in the alert
$alert-md-checkbox-border-color-off darken($list-md-border-color, 40%) Border color of the checkbox in the alert when off
$alert-md-checkbox-border-color-on $alert-md-button-text-color Border color of the checkbox in the alert when on
$alert-md-checkbox-icon-top 0 Top of the icon in the checkbox alert
$alert-md-checkbox-icon-left 3px Left of the icon in the checkbox alert
$alert-md-checkbox-icon-width 6px Width of the icon in the checkbox alert
$alert-md-checkbox-icon-height 10px Height of the icon in the checkbox alert
$alert-md-checkbox-icon-border-width 2px Border width of the icon in the checkbox alert
$alert-md-checkbox-icon-border-style solid Border style of the icon in the checkbox alert
$alert-md-checkbox-icon-border-color color-contrast($colors-md, $alert-md-checkbox-border-color-on) Border color of the icon in the checkbox alert
$alert-md-checkbox-icon-transform rotate(45deg) Transform of the icon in the checkbox alert

Sass Variables

  • Windows Platform
属性 默认 描述
$alert-wp-backdrop-background #fff Background of the alert backdrop
$alert-wp-width 100% Width of the alert
$alert-wp-max-width 520px Max width of the alert
$alert-wp-border-width 1px Border width of the alert
$alert-wp-border-style solid Border style of the alert
$alert-wp-border-color color($colors-wp, primary) Border color of the alert
$alert-wp-border-radius 0 Border radius of the alert
$alert-wp-background #e6e6e6 Background color of the alert
$alert-wp-head-padding 20px 22px 5px 22px Padding of the alert head
$alert-wp-head-text-align left Text align of the alert head
$alert-wp-title-font-size 20px Font size of the alert title
$alert-wp-title-font-weight 400 Font weight of the alert title
$alert-wp-sub-title-font-size 16px Font size of the alert sub title
$alert-wp-message-padding 0 22px 8px 22px Padding of the alert message
$alert-wp-message-padding-empty 0 Padding of the alert empty message
$alert-wp-message-text-color #000 Text color of the alert message
$alert-wp-message-font-size 13px Font size of the alert message
$alert-wp-content-max-height 240px Maximum height of the alert content
$alert-wp-input-margin 5px 0 5px 0 Margin of the alert input
$alert-wp-input-padding 0 8px Padding on the alert input
$alert-wp-input-border-width 2px Border width of the alert input
$alert-wp-input-border-style $alert-wp-border-style Border style of the alert input
$alert-wp-input-border-color $input-wp-border-color Border color of the alert input
$alert-wp-input-border-color-focused color($colors-wp, primary) Border color of the alert input when focused
$alert-wp-input-line-height 3rem Line height of the alert input
$alert-wp-input-text-color #000 Color of the text in the alert input
$alert-wp-button-padding 5px Padding of the alert button
$alert-wp-button-width 49.5% Width of the alert button
$alert-wp-button-border-radius 0 Border radius of the alert button
$alert-wp-button-font-weight 400 Font weight of the alert button
$alert-wp-button-text-color #000 Color of the text in the alert button
$alert-wp-button-background #b8b8b8 Background color of the alert button
$alert-wp-button-background-activated color-shade($alert-wp-button-background) Background color of the activated alert button
$alert-wp-button-margin-right 1% Margin right of the alert button
$alert-wp-button-group-padding 20px 22px 20px 22px Padding of the alert button group
$alert-wp-button-group-justify-content flex-end Justify content of the alert button group
$alert-wp-button-group-flex-wrap wrap-reverse Flex wrap of the alert button group
$alert-wp-button-group-vertical-width 100% Vertical width of the vertical alert button group
$alert-wp-button-group-vertical-margin-top 5px Margin top of the vertical alert button group
$alert-wp-radio-background color($colors-wp, primary) Background color of the radio alert
$alert-wp-radio-border-color $input-wp-border-color Border color of the radio alert
$alert-wp-radio-label-padding 13px 26px Padding of the label for the radio alert
$alert-wp-radio-label-text-color initial Text color of the label for the radio alert
$alert-wp-radio-label-text-color-checked $alert-wp-button-text-color Text color of the label for the checked radio alert
$alert-wp-radio-top 0 Top of the radio alert
$alert-wp-radio-left 13px Left of the radio alert
$alert-wp-radio-width 16px Width of the radio alert
$alert-wp-radio-height 16px Height of the radio alert
$alert-wp-radio-border-width 2px Border width of the radio alert
$alert-wp-radio-border-style solid Border style of the radio alert
$alert-wp-radio-border-radius 50% Border radius of the radio alert
$alert-wp-radio-border-color $input-wp-border-color Border color of the radio alert
$alert-wp-radio-icon-top 2px Top of the icon in the radio alert
$alert-wp-radio-icon-left 2px Left of the icon in the radio alert
$alert-wp-radio-icon-width 8px Width of the icon in the radio alert
$alert-wp-radio-icon-height 8px Height of the icon in the radio alert
$alert-wp-radio-icon-border-radius $alert-wp-radio-border-radius Border radius of the icon in the radio alert
$alert-wp-checkbox-label-padding 13px 26px Padding of the label for the checkbox in the alert
$alert-wp-checkbox-label-text-color initial Text color of the label for the checkbox in the alert
$alert-wp-checkbox-label-text-color-checked initial Text color of the label for the checked checkbox in the alert
$alert-wp-checkbox-top 0 Top of the checkbox in the alert
$alert-wp-checkbox-left 13px Left of the checkbox in the alert
$alert-wp-checkbox-width 16px Width of the checkbox in the alert
$alert-wp-checkbox-height 16px Height of the checkbox in the alert
$alert-wp-checkbox-border-width 2px Border width of the checkbox in the alert
$alert-wp-checkbox-border-style solid Border style of the checkbox in the alert
$alert-wp-checkbox-border-radius 0 Border radius of the checkbox in the alert
$alert-wp-checkbox-border-color $input-wp-border-color Border color of the checkbox in the alert
$alert-wp-checkbox-background-off transparent Background color of the checkbox in the alert when off
$alert-wp-checkbox-background-on color($colors-wp, primary) Background color of the checkbox in the alert when on
$alert-wp-checkbox-icon-top -2px Top of the icon in the checkbox alert
$alert-wp-checkbox-icon-left 3px Left of the icon in the checkbox alert
$alert-wp-checkbox-icon-width 6px Width of the icon in the checkbox alert
$alert-wp-checkbox-icon-height 12px Height of the icon in the checkbox alert
$alert-wp-checkbox-icon-border-width 1px Border width of the icon in the checkbox alert
$alert-wp-checkbox-icon-border-style solid Border style of the icon in the checkbox alert
$alert-wp-checkbox-icon-border-color color-contrast($colors-wp, $alert-wp-checkbox-background-on) Border color of the icon in the checkbox alert
$alert-wp-checkbox-icon-transform rotate(45deg) Transform of the icon in the checkbox alert

results matching ""

    No results matching ""