Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Pass element using ng-show AngularJS

HTML

<li ng-show="sample($event)" TestLi</li>

Javascript

$scope.sample = function($event){ //$event is undefined
//do something 
}

I've only tried passing the html element using ng-click but is there a way to pass it using ng-show?.

like image 842
user3770093 Avatar asked Aug 05 '26 18:08

user3770093


1 Answers

The attribute ng-show, ng-hide and ng-if usually evaluate expression and not function. You can read about it here:

https://docs.angularjs.org/api/ng/directive/ngShow

However, if you really wish to get the target element, you may try writing a very simple directive.

<li ng-show="sample($event)" getTarget> TestLi</li>

app.directive("getTarget", function() {
    return {
        link: function(scope, element, attrs) {
            console.log(element);
        }
    }
});
like image 110
ShivangiBilora Avatar answered Aug 07 '26 13:08

ShivangiBilora



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!