0

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

enter image description here

I need to input hours as 08 and minutes 05 But visible 8 and 5. How can do that?

If not clear, comment. Hope answer soon.

3
  • 2
    Is there a reason not to use <input type=time>? Commented Sep 11, 2015 at 12:53
  • Feel free to accept an answer if any of them helped you out. Commented Sep 11, 2015 at 18:52
  • @Blindy maybe because it is not supported in Safari or Internet Explorer 12 and earlier versions Commented Jan 26, 2021 at 9:51

2 Answers 2

6

You 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;
  }
}
Sign up to request clarification or add additional context in comments.

Comments

2

I would suggest to create a filter to add '0' before number if needed

https://stackoverflow.com/a/17648547/274500

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.