如何申请条件ng-class?

时间:2016-08-05 07:38:23

标签: angularjs

这是我的发送按钮,它有两个选项1发送激活电子邮件和第二个重置密码。现在我waana应用重置测试类重置密码列表项,如果userstatus被通知或添加,所以想要添加条件语句。我试过但是这个没用。皮斯帮助。

var theToggle = document.getElementById('toggle');

function hasClass(elem, className) {
    return new RegExp(' ' + className + ' ').test(' ' + elem.className + ' ');
}

function addClass(elem, className) {
    if (!hasClass(elem, className)) {
        elem.className += ' ' + className;
    }
}

function removeClass(elem, className) {
    var newClass = ' ' + elem.className.replace( /[\t\r\n]/g, ' ') + ' ';
    if (hasClass(elem, className)) {
        while (newClass.indexOf(' ' + className + ' ') >= 0 ) {
            newClass = newClass.replace(' ' + className + ' ', ' ');
        }
        elem.className = newClass.replace(/^\s+|\s+$/g, '');
    }
}

function toggleClass(elem, className) {
    var newClass = ' ' + elem.className.replace( /[\t\r\n]/g, " " ) + ' ';
    if (hasClass(elem, className)) {
        while (newClass.indexOf(" " + className + " ") >= 0 ) {
            newClass = newClass.replace( " " + className + " " , " " );
        }
        elem.className = newClass.replace(/^\s+|\s+$/g, '');
    } else {
        elem.className += ' ' + className;
    }
}

theToggle.onclick = function() {
   toggleClass(this, 'on');
   return false;
}

CSS

<div class="active-send-select" pull-left btn-group title="{{::'title.active.filter' | translate}}">
    <button class="btn btn-large dropdown-toggle" data-toggle="dropdown" ng-disabled="!actionButtonStatus.SENT">
        <i class="fa fa-envelope fa-lg"></i>
        <span class="action-button-text">{{::'label.button.send' | translate}}</span>
        <i class="icon-chevron-down pull-right" style="margin-top:-20px;"></i>
    </button>
    <ul class="dropdown-menu filter-state">
        <li class="abc"><a href="" ng-click="userstatus == 'Complete'||sendActivationNotification()"><span ng-class="{resettest: userstatus == 'Complete'}">{{::'label.dropdown.sendActivation' | translate}}</span></a></li>
       <li class="abc">
           <a href="" ng-click="userstatus == 'Notified' || onSendPasswordReset()"><span ng-class="{resettest: userstatus == 'Notified' || 'Added'}">{{::'label.dropdown.resetPassword' | translate}}</span></a>
        </li>
    </ul>
</div>

1 个答案:

答案 0 :(得分:0)

您可以使用简单的class代替ng-class

来执行此操作
<span class="{{userstatus == 'Notified' || 'Added'?'resettest': ' '}}">
{{::'label.dropdown.resetPassword' | translate}}
</span>

但是我不明白你为什么试图用不同的条件两次添加resettest课程