我修好了。 (注意我使用了一个图标插件,所以如果你没有在你的应用程序中安装它们,这些通常不适合你):
<i primary range-left class="fa fa-bicycle"></i>
<i primary range-right class="fa fa-train"></i>
HTML:
<ion-list-header>
<ion-badge item-right>{{ trainvalue }}</ion-badge>
</ion-list-header>
<ion-item>
<ion-range min="0" max="400" pin="false" step="100" snaps="true" [(ngModel)]="train" color="primary" (ngModelChange)="onChangeTrain($event)">
<i primary range-left class="fa fa-bicycle"></i>
<i primary range-right class="fa fa-train"></i>
</ion-range>
</ion-item>
TS:
export class MyFancyClass {
train = 200;
trainvalue: any;
textChangeTrain: any;
}
constructor(public navCtrl: NavController, public navParams: NavParams) {
this.textChangeTrain = ["Not Important", "Not that Important", "Neutral", "Important", "Very Important"];
this.trainvalue = this.textChangeTrain[2];
}
onChangeTrain() {
if (this.train == 0) { this.trainvalue = this.textChangeTrain[0] }
if (this.train == 100) { this.trainvalue = this.textChangeTrain[1] }
if (this.train == 200) { this.trainvalue = this.textChangeTrain[2] }
if (this.train == 300) { this.trainvalue = this.textChangeTrain[3] }
if (this.train == 400) { this.trainvalue = this.textChangeTrain[4] }
}
它是如何工作的:
这会检查 Range 是否正在被使用。
(ngModelChange)="onChangeTrain($event)"
这就是它的功能。
如果 Range 的值为“0”,那么我们从 {{trainvalue}} 调用 this.trainvalue,它会检查数组中的正确数字并将其替换为文本。
onChangeTrain() {
if (this.train == 0) { this.trainvalue = this.textChangeTrain[0] }
这用于声明我们的值。火车= 200;将 Range 设置为默认值 200,trainvalue:any;使我们能够使用与 textChangeTrain 相同的值执行任何操作:any;
train = 200;
trainvalue: any;
textChangeTrain: any;
在这里,我们添加数组并将 trainvalue 设置为 [2],这意味着我们将其设置为 200,但我们写入 [2] 因为我们是从数组中调用它。
this.textChangeTrain = ["Not Important", "Not that Important", "Neutral", "Important", "Very Important"];
this.trainvalue = this.textChangeTrain[2];
}
我希望这对将来的某人有所帮助,编码愉快。