angular-从ng-disabled访问元素 [英] angular - access the element from ng-disabled

查看:138
本文介绍了angular-从ng-disabled访问元素的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想通过ng-disablethis(元素)-一个button传递给我的controller. 这是我的HTML:

I want to pass this (the element) - a button to my controller by ng-disable. here is my HTML:

<button type ="button" class = "btn btn-default" ng-click= "open()" ng-disabled = "checkRowId(this)">
</button>

还有我的controller:

$scope.checkRowId = function(btn){
   console.log(btn); //undefined
}

原木靴undefined,有没有办法通过ng-disabled传递elementbutton一样?

The log shoes undefined, is there a way to pass a element like a button via ng-disabled?

推荐答案

没有直接方法可以通过ng-disabled来传递元素.您可以创建一个指令"disabled-ele",然后在其中放置元素禁用逻辑.

There is no direct way to pass element via ng-disabled. You can create one directive say "disabled-ele" and put your element disabling logic there.

示例代码:

.directive('disabledEle', function() {
                    return {
                        restrict: 'EA',
                        link: function(scope, element, attrs) {
                            if(attrs.disabledEle.toLowerCase() === 'true') {
                                element.attr('disabled', 'disabled');
                            } else {
                                element.removeAttr('disabled');
                            }
                        }
                    }
                });

<button type ="button" value="Click" class = "btn btn-default" disabled-ele="false">Click
                    </button>

这篇关于angular-从ng-disabled访问元素的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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