角度:悬停更新范围 [英] angular: updating scope on hover

查看:103
本文介绍了角度:悬停更新范围的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想一个主分区的某些子格,当你将鼠标悬停在主分区被默认的隐藏可见

I'd like some child div of a main div be hidden by default an visible when you hover over the main div.

我想有一个角在本地和忘记的jQuery的 .hover()办法。

I'm trying to have that native in angular and forget the .hover() way in jquery.

不过,我觉得关于使用 NG-节目对孩子的div,然后更新绑定时我将鼠标悬停在主分区。有没有一个指令,监听徘徊?

I though about using ng-show on the child div and then updating the binding when I hover the main div. Is there a directive to listen for hovering?

推荐答案

您是在正确的轨道上。实际上,你可以使用ngMouseenter和ngMouseleave指令来做到这一点。

You're on the right track. You can actually use the ngMouseenter and ngMouseleave directives to do this.

<span ng-mouseenter="show = true" ng-mouseleave="show = false">
  Mouse over me.
</span>

<div ng-show="show">Hello!</div>

下面是一个工作Plunker:<一href=\"http://plnkr.co/edit/Ro80nR7HT7OGGPCXjz7E?p=$p$pview\">http://plnkr.co/edit/Ro80nR7HT7OGGPCXjz7E?p=$p$pview

Here's a working Plunker: http://plnkr.co/edit/Ro80nR7HT7OGGPCXjz7E?p=preview

@ Swordfish0321也是正确的 - 你可以写一个非常简单的指令,专门为悬停听,如果你愿意,但它可能没有必要。我们使用的mouseenter 鼠标离开中的 UI引导,例如。

@Swordfish0321 is also right - you can write a very simple directive to listen specifically for the hovering if you'd like, but it may not be necessary. We use mouseenter and mouseleave for tooltips in UI Bootstrap, for example.

这篇关于角度:悬停更新范围的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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