使用ng-show AngularJS传递元素 [英] Pass element using ng-show AngularJS

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

问题描述

HTML

HTML

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

Javascript

Javascript

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

我只尝试使用ng-click传递html元素,但是有没有办法使用ng-show?来传递它。

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

推荐答案

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);
        }
    }
});

这篇关于使用ng-show AngularJS传递元素的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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