[Angular] 암호 일치성 확인 directive

2175 단어

Angular 암호 정합성 확인


password check directive in angularjs
// directives.js
'use strict'

angular.module('fooApp')
    .directive('passMatch', function () {
        return {
            // restrict: 'A', // only activate on element attribute
            require: 'ngModel', // get a hold of NgModelController
            link: function (scope, elem, attrs, model) {
                if (!attrs.passMatch) {
                    console.error('passMatch expects a model as an argument!');
                    return;
                }
                scope.$watch(attrs.passMatch, function (value) {
                    // Only compare values if the second ctrl has a value.
                    if (model.$viewValue !== undefined && model.$viewValue !== '') {
                        model.$setValidity('passMatch', value === model.$viewValue);
                    }
                });
                model.$parsers.push(function (value) {
                    // Mute the nxEqual error if the second ctrl is empty.
                    if (value === undefined || value === '') {
                        model.$setValidity('passMatch', true);
                        return value;
                    }
                    var isValid = value === scope.$eval(attrs.passMatch);
                    model.$setValidity('passMatch', isValid);
                    return isValid ? value : undefined;
                });
            }
        }
    });
Must be equal!

참조 연결

  • AngularJS Directive to check that passwords match
  • password check directive in angularjs
  • jsfiddle demo

  • Directive Resources

  • Angular Custom Directive in Component Style
  • AngularJS 내막 상세의 Directive
  • angularJS directive 상세설명
  • 좋은 웹페이지 즐겨찾기