I’m trying to make at tidy version of the ion-range component that allows for values such as 0.05 and relevant ‘steps’. This is just an automation of the idea of multiplying the value by some constant when changed, and dividing by the same constant when displaying. It’s been discussed here before.
example:
<ion-item>
<ion-label>Discharge Voltage -
<ion-badge>{{preset.discharge_voltage}}V</ion-badge>
</ion-label>
<ion-range [ngModel]="preset.discharge_voltage * 10"
(ngModelChange)="preset.discharge_voltage=$event/10"
[min]="this.preset.dischargeVoltageMinMax().min * 10"
[max]="this.preset.dischargeVoltageMinMax().max * 10">
<ion-label range-left>{{this.preset.dischargeVoltageMinMax().min}}V</ion-label>
<ion-label range-right>{{this.preset.dischargeVoltageMinMax().max}}V</ion-label>
</ion-range>
</ion-item>
I’m trying to generalize this. However; I can’t get the ion-range component to render ng-content. At all. The content will render if I have my block outside of ion-range. Any way around this? Looks like ion-range doesn’t render subcontent (i.e: doesn’t do projection), but I can’t find the src to look at to confirm that (not sure where to find the ion-range template, if it even exists anywhere).
better-range.ts
import {Component, EventEmitter, Input, Output} from '@angular/core';
@Component({
selector: 'better-range',
templateUrl: 'better-range.html',
})
export class BetterRangeComponent {
@Input() disabled: boolean = false;
@Input() pin: boolean = false;
@Input() multiplier: number = 1;
@Input() min: number = 0;
@Input() max: number = 10;
@Input() value: number = 0;
@Output() valueChange: EventEmitter<any> = new EventEmitter();
constructor() {
}
}
better-range.html
<ion-range [ngModel]="value * multiplier"
(ngModelChange)="value=$event / multiplier"
pin="{{pin}}"
disabled="{{disabled}}"
[min]="min_val * multiplier"
[max]="max_val * multiplier"
>
<ng-content></ng-content>
</ion-range>
Resulting render:
Any suggestions or ideas I might try?
Where would I find the template source for ion-range, to check my assumption?