小编Jes*_*ier的帖子

添加ng-pattern属性的指令

我正在尝试创建一个将使用ng-pattern属性替换自身的指令.该属性应用于输入元素,但此后元素基本上变得不可用.我无法再在文本框中输入字符.

这是plunkr http://plnkr.co/edit/F6ZQYzxd8Y04Kz8xQmnZ?p=preview

我想我必须在添加属性后错误地编译元素.

app.directive('passwordPattern', ['$compile', function($compile){
    return{
    compile: function (element, attr){

        element.removeAttr('password-pattern');
        element.attr('ng-pattern', '/^[\\w\\S]{6,12}$/');

        return {
            pre: function preLink(scope, iElement, iAttrs, controller) {  },
            post: function postLink(scope, iElement, iAttrs, controller) {
                $compile(iElement)(scope);
            }
        };
    }
};
}]);
Run Code Online (Sandbox Code Playgroud)

任何关于解决方案的想法或文本框变得无法使用的原因都将非常值得赞赏.谢谢.

angularjs angularjs-directive

2
推荐指数
1
解决办法
2694
查看次数

标签 统计

angularjs ×1

angularjs-directive ×1