Custom form validation directive to compare two fields

后端 未结 6 812
借酒劲吻你
借酒劲吻你 2020-11-28 08:54

I\'m an angular newbie, and I\'m stumbling over something in how angular\'s form validation directives work.

I know that I can fairly easily add directives to in

6条回答
  •  情话喂你
    2020-11-28 09:49

    You may take a look at https://github.com/nelsonomuto/angular-ui-form-validation

    This provides a directive that is preconfigured with an api that exposes the scope and its models to your validator function.

    Here is a plunker with the your specific use case: http://plnkr.co/edit/S0rBlS?p=preview

    The syntax for the directives validators is as shown in the below example : { errorMessage: 'Cannot contain the number one', validator: function (errorMessageElement, val, attr, element, model, modelCtrl){ /** * The model and modelCtrl(scope) are exposed in the validator function * */ return /1/.test(val) !== true;
    } }

提交回复
热议问题