问题
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>
And my controller :
$scope.checkRowId = function(btn){
console.log(btn); //undefined
}
The log shoes undefined, is there a way to pass a element like a button via ng-disabled?
回答1:
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.
Example Code:
.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>
来源:https://stackoverflow.com/questions/37429563/angular-access-the-element-from-ng-disabled