Home > Article > Web Front-end > About the analysis of AngularJs Forms
This article mainly introduces AngularJs Forms. Here we have compiled relevant information and simple sample codes. Friends in need can refer to it
Controls (input, select, textarea) are a way for users to input data. A Form is a collection of these controls designed to group related controls.
Forms and controls provide validation services, so users can receive prompts for invalid input. This provides a better user experience because users can get immediate feedback and know how to correct errors. Keep in mind that while client-side validation plays an important role in providing a good user experience, it can be easily bypassed and, therefore, cannot be trusted. Server-side authentication is still necessary for a secure application.
1. Simple form
The key directive to understand two-way data binding is ngModel. ngModel provides two-way data binding from model to view and view to model. Moreover, it also provides APIs to other directives to enhance their behavior.
<!DOCTYPE HTML> <html lang="zh-cn" ng-app="SimpleForm"> <head> <meta charset="UTF-8"> <title>PropertyEvaluation</title> <style type="text/css"> .ng-cloak { display: none; } </style> </head> <body> <p ng-controller="MyCtrl" class="ng-cloak"> <form novalidate> 名字: <input ng-model="user.name" type="text"><br/> Email: <input ng-model="user.email" type="email"><br/> 性别: <input value="男" ng-model="user.gender" type="radio">男 <input value="女" ng-model="user.gender" type="radio">女 <br/> <button ng-click="reset()">还原上次保存</button> <button ng-click="update(user)">保存</button> </form> <pre class="brush:php;toolbar:false">form = {{user | json}}
saved = {{saved | json}}