Angularjs Angular在尝试动态更新时将输入字段设置为ng invalid min
我正试图更新一个Angularjs Angular在尝试动态更新时将输入字段设置为ng invalid min,angularjs,ionic-framework,ionic,Angularjs,Ionic Framework,Ionic,我正试图更新一个字段,具体取决于中选择的选项,以及它的min=”“和max=“”,但输入字段变为红色和空:爱奥尼亚将这些类放入标记中: class=“ng有效最大ng有效数字ng脏ng无效ng无效最小ng无效必需” 输入值类型上的console.log表明它们确实是数字 编辑:如果我在://下注释代码片段,请初始化重量和单位字段中的值 然后虫子就消失了 template.html <div id="weightdata" class="row">
字段,具体取决于
中选择的选项,以及它的min=”“
和max=“”
,但输入字段变为红色和空:爱奥尼亚将这些类放入标记中:
class=“ng有效最大ng有效数字ng脏ng无效ng无效最小ng无效必需”
输入值类型上的console.log
表明它们确实是数字
编辑:如果我在://下注释代码片段,请初始化重量和单位字段中的值
然后虫子就消失了
template.html
<div id="weightdata" class="row">
<div id="weighttext"> <!-- class="col-20 enteryourweighttext"> -->
My weight:
</div>
<input id="weightinput" type="number" name="userweight" min="{{data.minWeight}}" max="{{data.maxWeight}}" ng-model="data.userweight" ng-change="saveUserWeight()" required></input>
<div id="weightunitradios">
<ion-checkbox class="checkboxes" ng-model="data.weightunit" ng-true-value="kg" ng-false-value="lbs" ng-change="saveWeightUnit(); convertWeightInput();">kg</ion-checkbox>
<ion-checkbox class="checkboxes" ng-model="data.weightunit" ng-true-value="lbs" ng-false-value="kg" ng-change="saveWeightUnit(); convertWeightInput();">lbs</ion-checkbox>
</div>
</div>
截图:
如图所示
我们需要使用
ng min
和ng max
而不是min
和max
实际上,我必须将流程分成两个函数,如下所示:
if ($scope.data.weightunit === 'kg'){
$scope.data.minWeight=30;
$scope.data.maxWeight=140;
} else {
$scope.data.minWeight=65;
$scope.data.maxWeight=310;
}
if (sessionService.get('userWeight')) {$scope.data.userweight = parseInt(sessionService.get('userWeight')) } else {$scope.data.userweight = 70};
if (sessionService.get('userLevel')) {$scope.data.levelvalue = parseInt(sessionService.get('userLevel')) } else {$scope.data.levelvalue = 5};
$scope.changeMinMax = function () {
if ($scope.data.weightunit === 'kg'){
$scope.data.minWeight=30;
$scope.data.maxWeight=140;
} else {
$scope.data.minWeight=65;
$scope.data.maxWeight=310;
}
}
$scope.convertWeightInput = function () {
if ($scope.data.weightunit === 'kg'){
$scope.data.userweight = parseFloat(Math.round(lbs2kg($scope.data.userweight)));
console.log(typeof $scope.data.userweight);
console.log($scope.data.userweight);
} else {
$scope.data.userweight = parseFloat(Math.round(kg2lbs($scope.data.userweight)));
console.log(typeof $scope.data.userweight);
console.log($scope.data.userweight);
}
}
if ($scope.data.weightunit === 'kg'){
$scope.data.minWeight=30;
$scope.data.maxWeight=140;
} else {
$scope.data.minWeight=65;
$scope.data.maxWeight=310;
}
if (sessionService.get('userWeight')) {$scope.data.userweight = parseInt(sessionService.get('userWeight')) } else {$scope.data.userweight = 70};
if (sessionService.get('userLevel')) {$scope.data.levelvalue = parseInt(sessionService.get('userLevel')) } else {$scope.data.levelvalue = 5};
$scope.changeMinMax = function () {
if ($scope.data.weightunit === 'kg'){
$scope.data.minWeight=30;
$scope.data.maxWeight=140;
} else {
$scope.data.minWeight=65;
$scope.data.maxWeight=310;
}
}
$scope.convertWeightInput = function () {
if ($scope.data.weightunit === 'kg'){
$scope.data.userweight = parseFloat(Math.round(lbs2kg($scope.data.userweight)));
console.log(typeof $scope.data.userweight);
console.log($scope.data.userweight);
} else {
$scope.data.userweight = parseFloat(Math.round(kg2lbs($scope.data.userweight)));
console.log(typeof $scope.data.userweight);
console.log($scope.data.userweight);
}
}