This is code
<input type="number" class="form-control" min="0" max="12" step="1" ng-model="input.hours" required>
<input type="number" class="form-control" min="0" max="60" step="5" ng-model="input.minute" required>
This is browser preview
I need to input hours as 08 and minutes 05 But visible 8 and 5. How can do that?
If not clear, ment. Hope answer soon.
This is code
<input type="number" class="form-control" min="0" max="12" step="1" ng-model="input.hours" required>
<input type="number" class="form-control" min="0" max="60" step="5" ng-model="input.minute" required>
This is browser preview
I need to input hours as 08 and minutes 05 But visible 8 and 5. How can do that?
If not clear, ment. Hope answer soon.
Share Improve this question asked Sep 11, 2015 at 12:51 Amila SampathAmila Sampath 6454 gold badges11 silver badges28 bronze badges 3-
2
Is there a reason not to use
<input type=time>
? – Blindy Commented Sep 11, 2015 at 12:53 - Feel free to accept an answer if any of them helped you out. – Chrillewoodz Commented Sep 11, 2015 at 18:52
- @Blindy maybe because it is not supported in Safari or Internet Explorer 12 and earlier versions – Sebastien Commented Jan 26, 2021 at 9:51
2 Answers
Reset to default 6You can use ng-change
to insert a 0
before the value each time it changes:
<input type="number" class="form-control" min="0" max="12" step="1" ng-model="input.hours" required ng-change="onChange(input.hours)">
<input type="number" class="form-control" min="0" max="60" step="5" ng-model="input.minute" required ng-change="onChange(input.minute)>
$scope.onChange = function(val) {
if (val < 10) {
val = '0' + val;
}
}
I would suggest to create a filter to add '0' before number if needed
https://stackoverflow./a/17648547/274500