AngularJS Tutorial(13)from w3school
2015-08-04 09:27
531 查看
An AngularJS form is a collection of input controls.
input elements
select elements
button elements
textarea elements
Last Name:
form = {"firstName":"John","lastName":"Doe"}
master = {"firstName":"John","lastName":"Doe"}
ng-app="myApp"
ng-controller="formCtrl">
<form
novalidate>
First Name:<br>
<input
type="text" ng-model="user.firstName"><br>
Last Name:<br>
<input
type="text" ng-model="user.lastName">
<br><br>
<button
ng-click="reset()">RESET</button>
</form>
<p>form =
{{user}}</p>
<p>master =
{{master}}</p>
</div>
<script>
var app =angular.module('myApp', []);
app.controller('formCtrl', function($scope) {
$scope.master = {firstName: "John", lastName: "Doe"};
$scope.reset = function() {
$scope.user = angular.copy($scope.master);
};
$scope.reset();
});
</script>
Try it Yourself »
The ng-controller directive defines the application controller.
The ng-model directive binds two input elements to the
user object in the model.
The formCtrl function sets initial values to themaster object, and defines the
reset() method.
The reset() method sets the user object equal to the
master object.
The ng-click directive invokes the reset() method, only if the button is clicked.
The novalidate attribute is not needed for this application, but normally you will use it in AngularJS forms, to override standard HTML5 validation.
An AngularJS form is a collection of input controls.
HTML Controls
HTML input elements are called HTML controls:input elements
select elements
button elements
textarea elements
HTML Forms
HTML forms group HTML controls together.An AngularJS Form Example
First Name:Last Name:
form = {"firstName":"John","lastName":"Doe"}
master = {"firstName":"John","lastName":"Doe"}
Application Code
<divng-app="myApp"
ng-controller="formCtrl">
<form
novalidate>
First Name:<br>
<input
type="text" ng-model="user.firstName"><br>
Last Name:<br>
<input
type="text" ng-model="user.lastName">
<br><br>
<button
ng-click="reset()">RESET</button>
</form>
<p>form =
{{user}}</p>
<p>master =
{{master}}</p>
</div>
<script>
var app =angular.module('myApp', []);
app.controller('formCtrl', function($scope) {
$scope.master = {firstName: "John", lastName: "Doe"};
$scope.reset = function() {
$scope.user = angular.copy($scope.master);
};
$scope.reset();
});
</script>
Try it Yourself »
The novalidate attribute is new in HTML5. It disables any default browser validation. |
Example Explained
The ng-app directive defines the AngularJS application.The ng-controller directive defines the application controller.
The ng-model directive binds two input elements to the
user object in the model.
The formCtrl function sets initial values to themaster object, and defines the
reset() method.
The reset() method sets the user object equal to the
master object.
The ng-click directive invokes the reset() method, only if the button is clicked.
The novalidate attribute is not needed for this application, but normally you will use it in AngularJS forms, to override standard HTML5 validation.
相关文章推荐
- AngularJS Tutorial(12)from w3school
- AngularJS Tutorial(11)from w3school
- AngularJS Tutorial(10)from w3school
- AngularJS Tutorial(9)from w3school
- AngularJS Tutorial(8)from w3school
- AngularJS Tutorial(7)from w3school
- AngularJS Tutorial(6)from w3school
- AngularJS Tutorial(5)from w3school
- AngularJS Tutorial(4)from w3school
- AngularJS Tutorial(3)from w3school
- AngularJS Tutorial(2)from w3school
- AngularJS Tutorial(1)from w3school
- angularjs入门案例 新玩具-中午吃神马
- angular之Directive - Compile vs. Link
- angularjs calling order
- AngularJs学习笔记--Creating Services
- angular之directive定义对象说明
- Angularjs中的标签模式和html5模式
- 《AngularJS》5个实例详解Directive(指令)机制
- angularjs思维