Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Default value of input textbox in AngularJS

How do I set the default value of an input textbox in AngularJS so that it can be altered later? I wish to be able to submit the changed value of the textbox(using ng-model) to the server. Would using ng-value to set the initial value of the textbox be the correct approach in this case?

like image 556
Nipun Parasrampuria Avatar asked Jul 02 '15 21:07

Nipun Parasrampuria


People also ask

What is the default value of input?

Definition and Usage Note: The default value is the value specified in the HTML value attribute. The difference between the defaultValue and value property, is that defaultValue contains the default value, while value contains the current value after some changes have been made.

Which attribute at default value to the form input element?

The value attribute specifies the value of an <input> element. The value attribute is used differently for different input types: For "button", "reset", and "submit" - it defines the text on the button. For "text", "password", and "hidden" - it defines the initial (default) value of the input field.

What is default value of number?

For numeric types, the default is 0 , with the exception that for integer or floating-point types declared with the AUTO_INCREMENT attribute, the default is the next value in the sequence.

How do I set default selected value in ng options?

Use ng-init to set default value for ng-options . Save this answer. Show activity on this post. In my opinion the correct way to set a default value is to simply pre-fill your ng-model property with the value selected from your ng-options , angular does the rest.


1 Answers

Set the ngModel value:

<input type="text" ng-model="myInput" />

$scope.myInput = "Default";
like image 180
tymeJV Avatar answered Oct 11 '22 11:10

tymeJV