Original address: Http://code.angularjs.org/1.0.2/docs/guide/forms
Controls (input, select, textarea) are a way for users to enter data. A form (form) is a collection of these controls that are 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 the user can immediately get feedback and know how to fix the error. Keep in mind that while client-side validation plays an important role in providing a good user experience, it can be easily bypassed, so client-side validation is not trustworthy. Server-side validation is still necessary for a secure application.
First, simple form
The key directive for understanding bidirectional data binding is Ngmodel. Ngmodel provides two-way data binding from model to view and view to model. It also provides APIs to other directive to enhance their behavior.
<! DOCTYPE html>
<! DOCTYPE html>V. Implementing custom Form control (using Ngmodel)
Angular implements all of the HTML's underlying controls (Input,select,textarea) and is capable of most scenarios. However, if we need to be more flexible, we can implement the purpose of customizing the form control by writing a directive.
In order to make the control work with Ngmodel and implement bidirectional data binding, it requires:
- Implementing the Render method is responsible for rendering the data after executing and passing all Ngmodelcontroller. $formatters method.
- Call the $setviewvalue method, and the model needs to respond to updates whenever the user interacts with the control. This is usually implemented in the DOM event listener.
You can view $compileprovider.directive (http://www.cnblogs.com/lcllao/archive/2012/09/09/2677190.html) for more information.
The following example shows how to add a bidirectional data binding attribute to an element that can be edited.
<! DOCTYPE html> ANGULARJS Study Notes--forms