Empty or empty text field instead of a null value

I have a text box as shown below.

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

TotalUnitsCompletedmodel is a field int. Could you tell me how to set an empty or empty value instead 0in the text box above? This is currently displayed as 0. Thanks in advance.

Note. I do not like changing the model intto string.

+4
source share
1 answer

You just need to install item.TotalUnitsCompleted = undefined;

If you use ngTable, just ng-initin every loopng-init="item.TotalUnitsCompleted = undefined"

Here is an example:

<input type="number" ng-model="TotalUnitsCompleted"  ng-init="TotalUnitsCompleted = initTotalUnits(TotalUnitsCompleted)"/>

Controller:

app.controller('MainCtrl', function($scope) {
  $scope.TotalUnitsCompleted = 5;

  $scope.initTotalUnits = function(units) {
    return (typeof units !== 'undefined' && units > 0 && units !== null) ? units : undefined;
  }
});

Plunker

+2
source

Source: https://habr.com/ru/post/1606208/


All Articles