以下是我的项目的UI
大家好,我想问一下,我是否可以根据位置和年份传递值?这是我在ionic中的第一个项目,这是一个简单的计算器,但计算量取决于地点和年份。
例如,我将利率设置为10,然后在前面的索引中,我选择了位置英国,利率将除以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>发布于 2019-10-23 17:04:59
你的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);
}
}https://stackoverflow.com/questions/58517631
复制相似问题