对无效的返回值应用ng类

apply ng class on invalid return value

本文关键字:ng 应用 返回值 无效      更新时间:2023-09-26

我想将bootstrap has-error类应用于控制器中方法的无效返回。但我的尝试似乎都没有奏效。以下是我的做法:

<form role="form" name="configForm">
    <div class="form-group">
        <label class="control-label">Not between</label>
        <table class="table table-bordered table-hover table-condensed">
            <tr style="font-style:italic; font-weight: bold">
                <td style="width: 50%">Lower Bound</td>
                <td style="width: 50%">Upper Bound</td>
            </tr>
            <tr ng-repeat="bounds in themeComponents.components[compKey].boundaries.notBetween">
                <td>
                    <input name="betweenLowBound" class="form-control" ng-model="bounds.lower" ng-class="{'has-error' : checkBounds(bounds.lower, bounds.upper) == true }">
                </td>
                <td>
                    <input name="betweenUpperBound" class="form-control" ng-model="bounds.upper" ng-class="{'has-error' : checkBounds(bounds.lower, bounds.upper) == true }">
                </td>
                <td>
                    <button type="button" ng-click="removeEasingItem(compKey, bounds)" class="btn btn-sm btn-danger">
                        <i class="glyphicon glyphicon-remove-circle">
                                           </i>
                    </button>
                </td>
            </tr>
        </table>
    </div>
</form>

这是我的简单值机控制器:

$scope.checkBounds = function (lower, upper) {
    if(lower > upper)
        return true;
    return false;
}

此外,我如何将其设计为内联ng-if表达式,而不是控制器中的方法?当upperbound值大于lowerbound时,我希望td-input进入error状态。。

使用ng类动态添加css:ng-class="{ 'has-error': bounds.lower > bounds.upper}"