Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

AngularJS input type=number default value

Tags:

html

angularjs

New to Angular, and have this simple issue cannot get resolved: I have this html

<input type="number" max="20" step="0.1" name="est_mpg" id="est_mpg" data-ng-model="est.mpg" class="form-control" value="5.00" />

I cannot get default value to show up, what happens it flashes and than disappears, so the box is empty, and i can tick up/down from default min value. It worked fine until I turned the input to type="number" from text.

like image 438
Stas Svishov Avatar asked Mar 01 '14 18:03

Stas Svishov


People also ask

What is the default value of input type number?

The default stepping value for number inputs is 1 , allowing only integers to be entered—unless the stepping base is not an integer.

How do you set the value of an input type number?

The <input type="number"> defines a field for entering a number. Use the following attributes to specify restrictions: max - specifies the maximum value allowed. min - specifies the minimum value allowed.

What is number in angular?

The angular. isNumber() function in AngularJS is used to determine the parameter inside isNumber function is a number or not. It returns true if the reference is a number otherwise returns false.


2 Answers

Use GruffBunny' solution or as an alternative use ng-init instead of value:

 ng-init="est.mpg=5.00"

Fiddle: http://jsfiddle.net/aY8rE/

like image 138
Ivan Chernykh Avatar answered Oct 17 '22 17:10

Ivan Chernykh


Default the value of est.mpg to 5.00 in the controller and remove the value attribute.

like image 20
Gruff Bunny Avatar answered Oct 17 '22 19:10

Gruff Bunny