This article and we share the main is the front-end development of the necessary AngularJs Framework form development related basic knowledge, want to use and learn from everyone AngularJs helpful.
1. simple form submission;
2. more form elements;
3. initialize the form;
Code
<!doctype html>
<meta http-equiv= "Content-type" content= "text/html; Charset=utf-8 ">
<title>
LESSON 7
</title>
<link rel= "stylesheet" type= "Text/css" href= "Css/main.css"/>
<style>
#content1 {padding:16px;}
</style>
<body>
<form ng-submit= "Postform ()" >
<ul>
<li>
<label> Username:</label><input type= "text" ng-model= "form. UserName "/>
</li>
<li>
<label> Nickname:</label><input type= "text" ng-model= "form. Nickname "/>
</li>
<li>
<label> Age:</label><input type= "text" ng-model= "form. Age "/>
</li>
<li>
<label> is married:</label><input type= "checkbox" ng-model= "form. Ismarried "/>
</li>
<li>
<label> favorite Animals:</label>
<input type= "Radio" ng-model= "form. Lovedanimal "value=" dog "/> Dog "
<input type= "Radio" ng-model= "form. Lovedanimal "value=" cat "/> cat
</li>
<li>
<label> City of residence:</label>
<select ng-model= "form. Locationcity "
Ng-options= "Obj.text as Obj.value for obj in form. Locationcitylist "
>
<option value= "" > Please select City </option>
</select>
</li>
<li>
<input type= "Submit" value= " submission " />
</li>
</ul>
</form>
<ul>
<li>{{form. Username}}</li>
<li>{{form. Nickname}}</li>
<li>{{form. Age}}</li>
<li>{{form. Ismarried}}</li>
<li>{{form. Lovedanimal}}</li>
<li>{{form. Locationcity}}</li>
</ul>
<script src= "Scripts/angular-1.4.6.min.js" ></script>
<script>
var app = Angular.module ("Lesson", []);
App.controller ("Formctrl", function ($scope) {
$scope. forminitobj = {
UserName: "",
Nickname: "",
};
$scope. form = {};
$scope. form.locationcitylist = [
{text: " Beijing " , Value: " Beijing "},
{text: " Shanghai " , Value: " Shanghai "},
{text: " Guangzhou " , Value: " guangzhou "}
];
$scope. Postform=function () {
Console.log ($scope. form);
$scope. Form = Angular.copy ($scope. forminitobj);
}
});
</script>
</body>
Execution results
original link:http://www.maiziedu.com/wiki/angularjs/develop/
Angularjs Getting Started form development