【问题标题】:How do I set text field for alert message in the alert dialog in Ionic 2?如何在 Ionic 2 的警报对话框中设置警报消息的文本字段?
【发布时间】:2018-10-23 19:59:24
【问题描述】:

我正在使用 Firebase 收到推送通知,并将其显示在警报框中。现在我想在文本字段中显示我收到的消息,以便用户可以编辑消息。我还想在控制台中输出消息。

pushObject.on('notification').subscribe((notification: any) => {
  if (notification.additionalData.foreground) {
    let youralert = this.alertCtrl.create({
      title: 'New Push notification',
      message: notification.message,
      buttons: [
        {
          text: 'Cancel',
          role: 'cancel',
          handler: () => {
           console.log('Cancel clicked');
          }
        },
        {
          text: 'Okay',
          handler: () => {
            console.log('Okay clicked');
          }
        }
      ]
    });

【问题讨论】:

    标签: ionic-framework ionic2 alert hybrid-mobile-app


    【解决方案1】:

    警报界面上有一个inputs 属性,它的工作方式与buttons 非常相似。它是一个对象数组,您有一个输入 value 属性来设置所需的值。

    由于我不知道你想在哪里记录你的值,如果它是来自服务器的值还是编辑后的值,我会同时显示。

    pushObject.on('notification').subscribe((notification: any) => {
      if (notification.additionalData.foreground) {
        console.log('push message', notification.message);
        let youralert = this.alertCtrl.create({
          title: 'New Push notification',
          inputs: [{
            placeholder: 'Your placeholder..',
            type: 'text',
            name: 'yourInputName, // Name to get it in your handler callback
            value: notification.message
          }],
          message: notification.message,
          buttons: [
            {
              text: 'Cancel',
              role: 'cancel',
              handler: () => {
               console.log('Cancel clicked');
              }
            },
            {
              text: 'Okay',
              // you'll need to get the input data, so pass a parameter to the callback
              handler: (data) => {
                // here's the value user has edited in the input
                console.log('Edited message', data.yourInputName);
                console.log('Okay clicked');
              }
            }
          ]
        });
    

    希望对你有帮助

    【讨论】:

      猜你喜欢
      • 2013-09-17
      • 1970-01-01
      • 2014-12-15
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多