setValueToStep()

Sets the value of the specified `Range` object to the value of the given `step`

Range.prototype.setValueToStep()

The method setValueToStep() sets the value of the specified Range object to the value of the given step.

If the given step is not within range the value is not changed.

range.class.ts
public setValueToStep(step: number): this {
  step > 0 && (this.value = this.getValueOfStep(step));
  return this;
}

Parameters

step:number

Step of number type to retrieve the value from the range and set it as the range current value.

Return type

Returns

The return value is the Range instance.

Example usage

// Example usage.
import { Range } from '@angular-package/range';

// Create new instance.
// Returns Range {min: 3, max: 27, value: 10} of Range<3, 27, 3>.
const range = new Range(3, 27, 10, 3);

// Cannot assign to 'value' because it is a read-only property.ts(2540)
// range.value = 12;

// Returns 9 of type number | undefined.
range.setValueToStep(3).value;

// Returns 27 of type number | undefined.
range.setValueToStep(9).value;

// Returns undefined of type number | undefined.
range.setValueToStep(11).value;

Last updated