How to optimize form validation

Source: Internet
Author: User

Angular.module (' Com.ngnice.app '). Directive (' Bffielderror ',functionBffielderror ($compile) {return {        //restricted to be used only in the form of attributes (Attribute).Restrict: ' EA ',        //there must be a Ng-model attribute on this element, and if not, it will be an error .Require: ' Ngmodel ',        //The link function is automatically executed when the current instruction is initializedLinkfunction(scope, element, Attrs, Ngmodel) {varSubscope = scope.$New(true); Subscope.haserror=function() {                returnNgmodel. $invalid &&Ngmodel. $dirty;            }; Subscope.errors=function() {                returnNgmodel. $error;            }; //compile a piece of HTML into a "live dom" and then pass the subscope to it, and the live DOM will automatically update itself with changes to Subscope            varhint = $compile (' <ul ng-if= ' Haserror () "><li ng-repeat=" (name, wrong) in errors () ">{{name|error}</li ></ul> ') (Subscope); //Append the live dom to the current element so that it appearselement.after (hint); }    };});

Angular.module (' Com.ngnice.app '). Constant (' Errors ', {    ' not a valid format e-mail address ',    ' This entry cannot be empty '});

function (Errors) {    returnfunction  (name) {        return Errors[name] | | name;}    );

How to optimize form validation

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.