$ scope.total< ng-min,$ scope.total未定义。
但我需要将这个值显示为变化。
例如:如果更改-50,那么如果他还需要50个,收银员可以轻松与客户交谈。
angular.module('app', [])
.controller('MainCtrl', function($scope) {
$scope.pay = null;
$scope.total = 1000;
$scope.change = 0;
$scope.check = function() {
$scope.change = $scope.pay - $scope.total;
console.log('pay = ' + $scope.pay + ' , total = ' + $scope.total + ' , change = ' + $scope.change);
};
});
<body ng-app="app" ng-controller="MainCtrl">
Total = {{ total }}
<input type="number" ng-model="pay" ng-min="total" ng-change="check()">
Change = {{ change }}
</body>
这里是我的plunkr http://plnkr.co/edit/4C9AuBI4q97VXXvXM59B?p=preview
答案 0 :(得分:0)
你根本不需要使用ng-min,因为这个指令只会传递正确的值,只需为change-function添加一个条件。 E.g
if($scope.change < 0){
//do something
}
另外,如果您想避免类型错误,最好将$scope.pay = null;
更改为$scope.pay = 0;