如何设置内部指令NG-禁用 [英] How to set ng-disabled inside directive

查看:93
本文介绍了如何设置内部指令NG-禁用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的指令有

link: function ($scope, $elm, $attrs) {
    var status = $scope.item.status
    if (status) {
        var statusName = status.name,
            item = $scope.item;
        if (statusName === 'USED') {
            $attrs.$set('ng-disabled', true); // this doesn't work
        } else {
            $elm.attr('ng-disabled', false);
        }
    }
}

所以,我的问题是:

So, my question is:

如何使用该指令适用NG-残疾人元素?

How to apply ng-disabled to element with this directive?

推荐答案

您会设置 NG-停用来一个范围的变量,例如:

You would set ng-disabled to a scope variable, ex:

<input ng-disabled="isDisabled" />

然后你的指令,在里面可以设置该变量:

And then inside your directive you can set that variable:

$scope.isDisabled = true;

这篇关于如何设置内部指令NG-禁用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆