![](/style/images/good.png)
![](/style/images/bad.png)
How to keep the default form 'ng-model'
source link: https://www.codesd.com/item/how-to-keep-the-default-form-ng-model.html
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.
How to keep the default form 'ng-model'
I have a input field say name
. i have added a ng-model
in it with default value of 'Enter your Name'. but now the form submit button gets enabled. how to prevent the submit button enable from the default value?
here is my code :
var app = angular.module('plunker', []);
app.controller('MainCtrl', function($scope) {
$scope.field = {};
$scope.field.name="Enter your Name"; //because of default value form enables.
});
HTML :
<form name="myForm">
<input type="text" name="name" id="name" ng-model="field.name" required>
<button type="submit" ng-disabled="myForm.$invalid" >Submit</button>
</form>
Use a placeholder
instead of name
. It has the intended effect without the above consequence.
<input type="text" name="name" id="name" placeholder="Enter your name" ng-model="field.name" required>
Related Articles
How to report the default form action after jquery ajax arrives?
How to set the default form in vb.Net?
How to keep the default column header context menu on devexpress?
How to keep the previous form entry when the user attaches a file
Kendo numerictextbox: how to keep the default value even when it has been deleted?
How to keep the default open material search view
How to keep the default page size of my site while resizing the browser
Android: How to keep the default number always even if the user wants to delete it, and how to delete the default number when the user enters a value?
How to change css for an item but keep the default values for its children
how to assign the default value in the form input field for the password?
Crm 2011 - How to define a default form based on the value of the attribute (without using Javascript)?
How to keep the COMBOBox drop-down list by selecting items
Django sets the default form values
How to reveal the default Safari download folder via Applescript?
Recommend
About Joyk
Aggregate valuable and interesting links.
Joyk means Joy of geeK