我在 View 中有这个代码:

<span id="l3-bridge" ng-click="redirect('l3bridge')" class="menu-opt">
    <img class="marginleft" src="/web/bundles/lima3main/images/icon-l3bridge.png">
    L3 Bridge
</span>

这是我的 Angular 重定向功能:
$scope.redirect = function(url) {

    var element = angular.element( $(this) );
    console.log(element);

}

我需要做的是从我单击的元素中获取 id 值(在本例中为 l3-bridge )。

从 jQuery 到 AngularJS 是否有任何等效的 $(this).attr('id')

编辑: 我的意思是,我需要 View 的元素 ID。我怎样才能用 Angular 做到这一点?

最佳答案

将 $event 传递给处理程序:

<span id="l3-bridge" ng-click="redirect($event, 'l3bridge')" class="menu-opt">
    <img class="marginleft" src="/web/bundles/lima3main/images/icon-l3bridge.png">
    L3 Bridge
</span>

$scope.redirect = function(obj, url) {

    var id = obj.target.attributes.id.value;

}

关于jquery - AngularJS 中 $(this) 的等价物是什么,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/24441092/

10-11 08:25