ANGULARJS Study Notes--forms

Source: Internet
Author: User

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.