功能未禁用NEXT按钮

时间:2016-03-18 06:40:50

标签: javascript jquery angularjs

我正在尝试在AngularJS中进行验证。我想做最大和最小验证。我已经为此编写了函数并在HTML文件中调用了该函数。函数显示错误消息,但无法禁用下一个按钮并接受错误的输入。这是我的功能

$scope.validate = function(NetProfit) {
    if (NetProfit < 100000 || NetProfit > 20000000) 
    {
        $scope.greeting = 'Please enter a value between 100000 and 20000000.';        
    } 
    else 
    {
        $scope.greeting = '';        
    }
};

这是我的HTML代码

<input ng-model="NetProfit" name="NetProfit" id="NetProfit" type="text" ng-pattern="/^\d+$/" ng-change='validate(NetProfit)' class="zoomIn" placeholder="Your Annual Net Profit" required>
<p class="ErrorMessage">
    {{greeting}}
</p>
<p class="ErrorMessage" ng-show="step5form.NetProfit.$error.pattern">
    Annual net profit cannot be characters.
</p>
<button class="Submit" ng-disabled="!step5form.$valid" ng-click="step = 6">Next</button>

1 个答案:

答案 0 :(得分:0)

如果您不想更改整个代码,只需将||(OR)条件添加到您的NEXT按钮。

<button class="Submit" ng-disabled="!step5form.$valid || greeting!='' " ng-click="step = 6">Next</button>

这是工作插件 https://plnkr.co/edit/yOdQO2TMxjmLVV14u5ub?p=preview