我有数字文本框,如下所示.
<input type="number" ng-model="item.TotalUnitsCompleted" />
TotalUnitsCompleted模型是一个int字段.所以你能告诉我如何在上面的文本框中设置空值或空值而不是0吗?此时它显示为0.先谢谢.
注意:我不喜欢将int模型更改为string.
最佳答案 你只需要设置item.TotalUnitsCompleted = undefined;
如果你正在使用ngTable,只需在每个循环上使用ng-init ng-init =“item.TotalUnitsCompleted = undefined”
这是一个例子:
<input type="number" ng-model="TotalUnitsCompleted" ng-init="TotalUnitsCompleted = initTotalUnits(TotalUnitsCompleted)"/>
控制器:
app.controller('MainCtrl', function($scope) {
$scope.TotalUnitsCompleted = 5;
$scope.initTotalUnits = function(units) {
return (typeof units !== 'undefined' && units > 0 && units !== null) ? units : undefined;
}
});