简体   繁体   English

从离子中的警报中获取价值

[英]Get value from alert in ionic

I am using ionic 3 and i want to get the input and add some autocomplete on it using google maps. 我正在使用离子3,我想获得输入并使用谷歌地图添加一些自动完成。 I have the following alert in my .ts file. 我的.ts文件中有以下警报。

let alert = this.alertCtrl.create({
    title: 'Offer a Ride',
    inputs: [
      {
        name: 'From',
        placeholder: 'From',
        id: 'From'
      },
      {
        name: 'To',
        placeholder: 'To',
        type: 'text',
        id: 'To'
      },
      {
        name: 'Date',
        placeholder: 'Date',
        type: 'date'
      }
    ],
    buttons: [
      {
        text: 'Cancel',
        role: 'cancel',
        handler: data => {
          console.log('Cancel clicked');
                elem.style.filter='none';
        }
      },
      {
        text: 'Offer',
        handler: data => {
          elem.style.filter='none';
          var from = data.From;
          var to = data.To;
          //this.navCtrl.setRoot (TabsPage, {from:from, to:to});
            let toast = this.toastCtrl.create({
            message: 'Location was set Successfully',
            duration: 3000
          });
          toast.present();
        }
      }
    ]
  }); 

I want to do the following: 我想做以下事情:

var autocomplete;
autocomplete = new google.maps.places.Autocomplete(
          (document.getElementById('From')),
          {types: ['geocode']});

However, I cannot get the input of id 'From'. 但是,我无法获得id'From'的输入。 Any idea how to do this? 知道怎么做吗?

I am not able to get you. 我无法得到你。 You can access the "From" field value inside the button handler, right? 您可以访问按钮处理程序中的“From”字段值,对吗?

Do you want to access the "From" field outside the handler? 您想要访问处理程序外部的“发件人”字段吗? In that case you can either use a global variable or a service to access the value. 在这种情况下,您可以使用全局变量或服务来访问该值。

Or do you want to access the field value by id? 或者您想通过ID访问字段值? In that case, theres an issue with the alert controller. 在这种情况下,警报控制器存在问题。 The id attribute is never written to the DOM for the alert. id属性永远不会写入警报的DOM。 Theres a bug reported for the same on the github. 在github上报告了同样的错误。

Here's the link AlertController - Input missing id attribute from Input Options 这是链接AlertController - 输入选项中输入缺少的id属性

Not sure if it answers your question. 不确定它是否回答了你的问题。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM