空白或空的数字文本框,而不是零值

Blank or empty number text box instead of zero value

本文关键字:数字 文本 空白      更新时间:2023-09-26

我有一个数字文本框,如下所示。

<input type="number" ng-model="item.TotalUnitsCompleted" />

CCD_ 1模型是一个CCD_。那么你能告诉我如何在上面的文本框上设置一个空白或空值而不是0吗?此时显示为0。提前谢谢。

注意:我不喜欢将int型号更改为string

您只需要设置item.TotalUnitsCompleted = undefined;

如果使用ngTable,则在每个循环TotalUnitsCompleted0 上仅使用ng-init

下面是一个例子:

<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;
  }
});

Plunker