在这种情况下如何使用ng-mouseenter删除类

时间:2015-08-06 16:14:58

标签: javascript angularjs angularjs-directive angularjs-ng-class

divticker上,我想在用户pulse之后删除ng-mouseenter CSS动画类。

我没有针对ticker div的指令设置,但在这种情况下是否有一种简单的方法可以删除或更新pulse类?

标记

<ul>
    <li ng-repeat="tik in tgh.tag.tickers">
        <div class="tag-container" ng-mouseleave="tgh.leaveAssoTicker(tik)">
            <div class="ticker"
                 ng-class="{'fade-1 pulse' : tgh.tag.mainSearch}"
                 ng-mouseenter="tgh.hoverAssoTicker(tik)"
                 ng-click="tgh.selectTicker(tik)">{{tik.ticker}}</div>
            <ticker-hover ticker="tik"></ticker-hover>
        </div>
    </li>
</ul>

mouseenter功能

function hoverAssoTicker(ticker, type) {
    vs.tickerTagsHoverTimeout = $timeout(function() {

        var theTicker = {};

        if (ticker.ticker === undefined) {
            theTicker.ticker = ticker;
        } else {
            theTicker.ticker = ticker.ticker;
        }

        ApiFactory.getTickerDetails(theTicker.ticker).then(function(data) {

            ticker.longname = data.data.tickers[0].longname;

            if (type === 'portfolio') {
                ticker.removePortfolio = true;
            }
            else if (type === 'searched') {
                ticker.addPortfolio = true;
            }
            else {
               ticker.removePortfolio = false,
               ticker.addPortfolio    = false;
            }

            ticker.tickerHoverDisplay = true;
        });

        vs.closeTagsTikHoverTimer = $timeout(function() {
            if (ticker.tickerHoverDisplay) ticker.tickerHoverDisplay = false;
        }, 2000);

        $rootScope.$broadcast(vs.closeTagsTikHoverTimer);
    }, 500);
}

1 个答案:

答案 0 :(得分:2)

我会使用绑定变量并在ng-class中使用它,例如ticker.isMouseover。然后在ng-mouseenter事件中,将其设置为true,反之亦然ng-mouseleave

然后你可以拥有ng-class="{pulse: !tik.isMouseover}"

之类的东西