ionic密码指令

密码显示、隐藏指令
1 drPassword指令

directives.directive('drPassword', function () {
return {
    restrict:'AE',
    replace:true,
    scope:{drModel:'='},
    templateUrl:'js/directive/tpl/tpl-password.html',
    link: function (scope,element, attrs) {
        var input = element.find('input');
        if (angular.isDefined(attrs.ngMinlength)){
            input.attr('ng-minlength',attrs.ngMinlength);
        }
        if (angular.isDefined(attrs.placeholder)){
            input.attr('placeholder',attrs.placeholder);
        }
        scope.passtype = 'password';
        scope.eyeclass=false;
        scope.togglePass = function () {
            if(scope.passtype=='password'){
                scope.passtype = 'text';
                scope.eyeclass=true;
            }else{
                scope.passtype = 'password';
                scope.eyeclass=false;
            }
        }
    }
}
});

2 tpl-password.html
这个模板内容也可根据你们的需求,进行调整,注意item要用div,不能用label,否则图片获取不到焦点。

<div class="item item-input">
<i class="icon ion-android-lock positive padding-right"></i>
    <input type="{{passtype}}"  ng-model="drModel" autocomplete="off" required  />
        <i class="icon ion-ios-eye padding-right" ng-class="{true:'positive'}[eyeclass]" ng-click="togglePass()" ></i>
</div>

3 html中使用
controller不需要做什么处理,这也是 angularjs的强项

<dr-password placeholder="请设置密码" dr-model="user.password" ng-minlength="6"  ></dr-password>
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

warrah

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值