javascript - Angular + jQuery .on() 不适用于 ng-repeat

标签 javascript jquery angularjs

当我通过 $http() 获取数据时,jQuery .on() 无法与 ng-repeat 一起使用。

工作正常:

<div ng-repeat="item in ['arrow-new', 'arrow-work', 'arrow-close']" class="arrow {{item}}">
</div>

事件:

$(".arrow").on('mouseenter mouseleave', function (event) {
  if (event.type == 'mouseenter') {
    //Ok
  } else {
  }
});

但是当我使用 $http() 加载数组进行迭代时,如下所示:

<div ng-repeat="item in statused" class="arrow {{item}}">
</div>

$http({ method: 'GET', url: '/app/data/statuses.json' }).success(function (data) {
   $scope.statused = data;
});

我的箭头渲染得很好,但事件没有绑定(bind)。我在调试控制台中没有错误。 我该如何解决这个问题?

最佳答案

这里不需要使用jQuery,只需使用ngMouseenterngMouseleave然后您可以在 Controller 中定义处理程序:

标记(状态 => 状态):

<div ng-repeat="item in statuses" class="arrow {{item}}" 
    ng-mouseenter="handleEvent()" ng-mouseleave="handleEvent()"></div>

Controller :

$scope.handleEvent = function(){
    //add logic here
}

关于javascript - Angular + jQuery .on() 不适用于 ng-repeat,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24063503/

相关文章:

jQuery 或 CSS 选择器选择所有以某个字符串开头的 ID

javascript - javascript 中的构造函数和原型(prototype)

javascript - window.location.href 无法在 Internet Explorer 浏览器上运行?

c# - 用于从智能手机上的 GPS 位置获取附近商店名称的 API

javascript - 如何根据 JavaScript 中的键名称比较两个 JSON 值?

javascript - 更改外部 html 标题事件菜单

jquery - 将 div 左上角的一组图像与 css 对齐

javascript - 想要通过提供错误来防止用户在文本字段中输入任何空格

jquery - 在 jQuery 中向 this 添加字符串

javascript - AngularJS 的子列表数量未知