如何检查是否元素有类AngularJS? [英] How to check if element has class with AngularJS?

查看:126
本文介绍了如何检查是否元素有类AngularJS?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个关闭面板菜单上的站点工作完美。用户可以打开和使用既是一个navicon或手指滑动它关闭。

I have an off panel menu working perfectly on a site. The user can open and close it using both a navicon or sliding it with the finger.

现在我有一个点击时从菜单图标转换到X图标(和打开的菜单)和周围的其他方式再次点击,菜单关闭时,一个非常漂亮的navicon图标。 Buuut如果用户滑动菜单打开或代替关闭使用navicon的,过渡不会被触发,这可能会导致对UX的混淆(即正在关闭菜单,示出了常规的3条水平线,而不是一个X的navicon图标)。

Right now I have a very nice navicon icon that transitions from Menu Icon to X Icon when is clicked (and opens the menu) and the other way around when is clicked again and the menu closes. Buuut if the user slides the menu open or closed instead of using the navicon, the transition is not triggered, which might lead to confusions on the UX (i.e. the menu being closed, and the navicon showing an X instead of the regular 3 horizontal lines icon).

因此​​,navicon有现在下面code触发过渡:

So, the navicon has right now the following code to trigger the transition:

ng-click="open = !open" ng-class="{'open-mob':open}">

我认为一个很好的和简单的方法来解决这个问题,将是菜单打开或关闭这个开放!=开每次触发,从关闭面板的JS会将类slidRight主部当菜单是开放的,而当它关闭时删除。

I thought that a nice and easy way to fix this, would be to trigger this "open = !open" every time that the menu is open or closed, as the js from the off panel adds the class slidRight to the main section when the menu is open, and removes it when it is closed.

照这样下去,有一些直接的方法来检查,如果类是有使用AngularJS?
如果类= slidRight - >!=开开

Being so, is there some straight way to check if the class is there using AngularJS? Something like if class = slidRight -> "open = !open".

谢谢!

推荐答案

角使用jqLit​​e的.hasClass()本身。

Angular uses jqLite's .hasClass() natively.

在这里阅读的角度文档的更多信息。

Read here on the angular docs for more info.

<一个href=\"http://docs.angularjs.org/api/angular.element\">http://docs.angularjs.org/api/angular.element

这篇关于如何检查是否元素有类AngularJS?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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