【问题标题】:Ionic Pass value from ion select and ion datetime to calculate离子选择和离子日期时间的离子通过值计算
【发布时间】:2023-04-06 17:34:01
【问题描述】:

UI for my indexicator

这是我的项目的用户界面

大家好,我想问一下我是否可以根据位置和年份传递价值?这是我在 ionic 中的第一个项目,它是一个简单的计算器,但计算的数量取决于位置和年份。

例如,我将比率设置为 10,然后在上一个索引中,我选择位置 UK,比率将除以 2,然后我输入 2011 年,它将再次除以 2。

在新索引之后,我将重复输入,但现在它将根据所选位置和年份相乘。

这是我的费率、位置和年份的 .html。我还包括一个按钮,将在离子输入占位符处显示总量。

我不知道在我的 .ts 中编写什么代码

 <ion-list>


<ion-item> 
  <ion-label stacked>Rate</ion-label>
<ion-input type="text" text-right id="input" ></ion-input>
</ion-item>  

 <br>
 <br>
  <ion-list-header>Previous Index</ion-list-header>

 <ion-list>
  <ion-item>
   <ion-label>Location</ion-label>
  <ion-select value="50" okText="Okay" cancelText="Dismiss">
  <ion-select-option value="50">UK</ion-select-option>
  <ion-select-option value="70">US</ion-select-option>
  <ion-select-option value="30">Canada</ion-select-option>

   </ion-select>
 </ion-item>

</ion-list>
  <ion-item>
    <ion-label>Year</ion-label>
     <ion-datetime [pickerOptions]="customPickerOptions" placeholder="Select One" 
   displayFormat="YYYY" min="2011" max="2019"></ion-datetime>
    </ion-item>

 <ion-button type ="submit">Total</ion-button>


  <div class="window"></div>
  <div class="input"><span>
      <ion-input type="text" placeholder="0" name="display">
      </ion-input>

【问题讨论】:

    标签: angular ionic-framework


    【解决方案1】:

    你的 html 应该是这样的,

     <ion-item>
        <ion-label>Location</ion-label>
        <ion-select (change)="onSelectionChanges($event)" [(ngModel)]="currentSelection" okText="Okay" cancelText="Dismiss">
              <ion-select-option selected="true" value="50">UK</ion-select-option>
              <ion-select-option value="70">US</ion-select-option>
              <ion-select-option value="30">Canada</ion-select-option>
        </ion-select>
     </ion-item>
    

    您可以将一些 onChange 事件绑定到 ion-select。并触发一些方法例如:onSelectionChanges()

    export class Example{
        currentSelection = '50';
    
        onSelectionChanges(event: any) {
            // Your logic to apply when selection happens, goes here
            //You can also get the value in the variable currentSelection
            console.log(this.currentSelection);
            //another way is to access the changed value from event
            console.log(event.target.value);
        }
    }
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2019-08-20
      • 1970-01-01
      • 2021-05-15
      • 1970-01-01
      • 1970-01-01
      • 2020-12-17
      • 1970-01-01
      相关资源
      最近更新 更多